Announcement Announcement Module
Collapse
No announcement yet.
Contextual Template Parameters Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Contextual Template Parameters

    As part of an application I am working on, I'm attempting to build a component that can be included many times on a single page with each instance using a different set of parameters. I understand that in the page XML I could just define the component multiple times with the appropriate url as follows:

    Web Script Component
    Code:
    <webscript>
      <shortname>Ads</shortname>
      <description>Component that displays the various Ads on the site.</description>
      <url>/components/ad/{channel}</url>
    </webscript>
    Page XML
    Code:
    <page>
    	<id>landing</id>
    	<title>page title</title>
    	<template-instance>landing-template</template-instance>
    	<authentication>none</authentication>
    	<order-id>0</order-id>	
    	<components>
    		<component>
    			<region-id>ad</region-id>
    			<url>/components/ad/502</url>
    		</component>
    		<component>
    			<region-id>ad</region-id>
    			<url>/components/ad/501</url>
    		</component>
    ...
    While this works, these components will change constantly and may even be different depending on the context of the page. To address this, I've created a component that acts a container for other components. Here is the ftl:

    Code:
    <!-- column -->
    <#list columnContent.columnComponent as columnComponent>
    	<#switch columnComponent.componentType>		
    		<#case "ad">
    			<!-- ad -->			
    			<@region id="column-ad" scope="page" />
    			<#break>
    	</#switch>
    </#list>
    What I'm looking for is a way to dynamically update the template {channel} parameter for the component being rendered based on the loop. So ideally, I would like to be able to do the following:

    Code:
    <!-- column -->
    <#list columnContent.columnComponent as columnComponent>
    	<#switch columnComponent.componentType>		
    		<#case "ad">
    			<!-- ad -->	
    		        <#assign channel = columnComponent.channel>
    			<@region id="column-ad" scope="page" />
    			<#break>
    	</#switch>
    </#list>
    But this doesn't work. The local "channel" is not assigned in the context. Anyone have any ideas?

    Thanks,
    Kevin

  • #2
    I should also mention that I'm using Java as my implementation method.

    Comment


    • #3
      Currently SpringSurf does not support nested components (although this is something we have been considering looking into). It is not possible to nest the <@region> FreeMarker tag as the rendering will not recurse into it.

      There's a few things I'd like a bit more information on if possible...

      Firstly, if the components change constantly, what is it about them that is consistent? If it is simply the framing of them then it could be solved through the use of custom chrome.

      If it is simply the region the components are bound to in the page template that is consistent and you want the contents to be different each time you reload the page?

      When you say you want to dynamically update the template parameters... what is the trigger of this dynamic event? Page load? (my assumption from you use of "ad" in your examples is that you want the same general content of a page to be loaded but vary the advertising that appears in consistently located components)

      Regards,
      Dave

      Comment


      • #4
        Originally posted by ddraper View Post
        When you say you want to dynamically update the template parameters... what is the trigger of this dynamic event? Page load? (my assumption from you use of "ad" in your examples is that you want the same general content of a page to be loaded but vary the advertising that appears in consistently located components)
        Exactly. The structure, including size and dimensions, of the ads remain constant, the content of the ad changes. The way we determine which ad content to display is based off of an ad "channel", which is specific to the page context. What I've done in the meantime is create a custom layout document that describes which components live in a given area of a page. Within that document, I store region specific configuration values that are placed on the Request and made available to the WebScripts. This works for now.

        On the topic of nesting regions, that is something I would find extremely useful.

        Comment


        • #5
          The data in a region binding can be a freemarker variable:

          <@region id="${somevalue}" scope="page" />

          so you can change that on the fly in your loop - does that help?

          We do exactly that to generate the Alfresco Share dashboards - which consist of a number of dynamically assigned component "slots" in a multi-column layout template.

          Kev

          Comment


          • #6
            I tried that and received an error stating the value must be a Scalar, which brought me down the path I did. I assumed that they could only be static strings.

            Comment


            • #7
              The value must be a simple string, but you can certainly use an expression that resolves to scalar value.

              Here's is an extract from the template file in the application we have that does this:

              Code:
                          <#list 1..column.components as component>
                             <@region id="${bindPrefix + '-' + (column_index + 1) + '-' + (component_index + 1)}" scope="page" protected=true/>
                          </#list>
              Cheers,

              Kev

              Comment

              Working...
              X