cancel
Showing results for 
Search instead for 
Did you mean: 

Problems creating new webscript

lemmy
Champ in-the-making
Champ in-the-making
Hi,

I'm trying to create a new webscript. webscripts\list\thumbnails.* is pretty much what I need. So I copied and renamed 3 files to pictures.*. I've updated pictures.get.desc.xml

pictures.get.desc.xml
<webscript>
  <shortname>List of pictures</shortname>
  <description>List of pictures</description>
  <url>/list/pictures</url>
</webscript>

pictures.get.html.ftl
<!– pictures start –>
<#if articles??>
   <!– if articles –>
    <#if articles.title??>
        <div class="interior-header">
            <h2 class="full-h">${articles.title}</h2>
            <#if articles.description??><p class="intheader-paragraph">${articles.description}</p></#if>
        </div>
    </#if>
   
    <div class="interior-content">
        <#if articles.assets?size == 0>
            ${msg('list.none')}
        <#else>
            <#if subTitle??><h3>${msg(subTitle)}</h3></#if>               
            <ul class="portfolio-wrapper">
                <#list articles.assets as article>     
                    <li>
                        <a href="<@makeurl asset=article force='long'/>${linkParam!''}"><img src="<@makeurl asset=article rendition='mediumPublicationThumbnail'/>" alt="${asset.title!''}" class="img-border" /></a>
                        <h3><a href="<@makeurl asset=article force='long'/>${linkParam!''}">${article.title!article.name}</a></h3>
                        <#if article.description??><p><@truncate value=article.description chars=100/></p></#if>
                    </li>
                </#list>
            </ul>
        </#if>
    </div>
</#if>
<!– pictures end –>

pictures.js

// Get the collection of articles indicated in the component properties
model.articles = collectionService.getCollection(context.properties.section.id, args.collection);

// If a link page is specified in the component properties then pass this to the view
if (args.linkPage != null)
{
   model.linkParam = '?view='+args.linkPage;
}

//If a sub title is specified in the component properties then pass this to the view
if (args.subTitle != null)
{
   model.subTitle = args.subTitle;
}

I shall be used in article1 page.
article1.xml

<?xml version="1.0" encoding="UTF-8"?>
<page>
   <id>articlepage1</id>
   <description>news article style page with medium image</description>
   <template-instance>two-block</template-instance>
   <authentication>none</authentication>
   <components>
      <component>
         <region-id>left1</region-id>
         <url>/article/style1</url>
      </component>      
      <component>
         <region-id>right1</region-id>
         <url>/related/articles</url>
      </component>   
      <component>
         <region-id>right2</region-id>
         <url>/facebook/like</url>
      </component>
      <component>
         <region-id>right3</region-id>
         <url>/list/pictures</url>
      </component>
   </components>
</page>

Requesting the corresponding url shows the first and last html-remarks in pictures.get.html.ftl but not <!– if articles –> The JavaScript Debugger is working but it doesn't stop in pictures.js. Refreshing webscripts with http://localhost:8080/alfresco/service/index or http://localhost:8080/share/service/index doesn't effect anything.

Am I missing something?

Thanks,
Lemmy
4 REPLIES 4

bremmington
Champ on-the-rise
Champ on-the-rise
It looks like your new component is expecting a parameter named "collection" to be passed to it, which it then uses to populate  "articles" in the controller:

model.articles = collectionService.getCollection(context.properties.section.id, args.collection);

However, your page definition isn't specifying the collection parameter, so articles will not be set. Therefore, the test in your component FreeMarker will return false:

<#if articles??>
and so the majority of the component won't render.

You probably want to change your page definition to look something like (using your collection name in place of "mypictures"):

      <component>
         <region-id>right3</region-id>
         <url>/list/pictures</url>
         <properties>
             <collection>mypictures</collection>
        </properties>        
      </component>

lemmy
Champ in-the-making
Champ in-the-making
Thanks, Brian. This works perfectly fine for static collection names. I need to calculate the name of the collection depending on the name of the article. This calculation should be done by the web script.

Any idea why it isn't started?

bremmington
Champ on-the-rise
Champ on-the-rise
Sorry, I'm not with you. Why what isn't started?

lemmy
Champ in-the-making
Champ in-the-making
Found it 🙂 The script was named picture.js instead of picture.get.js. Thanks for your immediate help. Highly appreciated.