Pass Parameter to Template?

The place to talk about things that are related to CMS Made simple, but don't fit anywhere else.
Locked
Squire4Hire
Forum Members
Forum Members
Posts: 43
Joined: Wed Dec 09, 2015 11:16 pm

Pass Parameter to Template?

Post by Squire4Hire »

Is it possible to pass parameter values into templates in order to reuse templates in similar but different ways?

For example, if all that's different between Template1 and Template2 is a call to a particular LISE instance, is it possible to pass a string value that indicates which LISE instance to use?

Example:

{LISETest1 action="category" template_category="filter" show_items="true"}

vs

{LISETest2 action="category" template_category="filter" show_items="true"}
User avatar
Rolf
Power Poster
Power Poster
Posts: 7825
Joined: Wed Apr 23, 2008 7:53 am
Location: The Netherlands
Contact:

Re: Pass Parameter to Template?

Post by Rolf »

- + - + - + - + - + - + -
LATEST TUTORIAL AT CMS CAN BE SIMPLE:
Migrating Company Directory module to LISE
- + - + - + - + - + - + -
Image
Squire4Hire
Forum Members
Forum Members
Posts: 43
Joined: Wed Dec 09, 2015 11:16 pm

Re: Pass Parameter to Template?

Post by Squire4Hire »

Sorry Rolf, this still doesn't quite make sense to me. It appears this still drives the need to create a new template for each use but base it on a main template. I get that and am currently using a similar structure.

I guess I need to try to explain more about what I have and what I'm trying to do.

Let's say I create a Core::Page template called base_template and use the structure you've outlined in that link.
I would then create a new template called something like Documents and implement the {extends file='cms_template:base_template'} tag in order to add items to the top, content, or script sections. No problem. The content section of the Documents template could do something like call action to a LISE Instance to display documents added using something like {LISEDocuments action="category" show_items="true'}

But what if I had multiple LISE instances that are displayed in the same way as the LISEDocuments? This would imply that I would have to have a template for each instance even though they are all the same aside from the Instance call.

Is there a suggested way to pass the equivalent of a LISE Instance tag through a Content page that is based on a 'base_template' instead of setting each of the Content pages to their own respective templates? I would assume that templates are meant to be recycled instead of replicated.

Right now I have 5 different templates made for 5 different document repositories that are all structured the same aside from their LISE Instance.

Any suggestions?
User avatar
velden
Dev Team Member
Dev Team Member
Posts: 3497
Joined: Mon Nov 28, 2011 9:29 am
Location: The Netherlands

Re: Pass Parameter to Template?

Post by velden »

Using template inheritance one would be recycling the template:

Page template with LISE call

Code: Select all

...
{block name="LISE"}{LISEInstance1}{/block}
...
The inheriting templates could look like this (complete):

Code: Select all

{extends file='cms_template:Page template with LISE call'}
{block name="LISE"}{LISEInstance2}{/block}

Code: Select all

{extends file='cms_template:Page template with LISE call'}
{block name="LISE"}{LISEInstance3}{/block}
So in this case you're not really duplicating code.

Passing parameters to a template: nope, but you are 'passing' a lot of information to a template anyway.

You could use a specific content block to let an editor type the LISE instance name and use some logic inside your template (it's possible to (mis)use the 'extra' blocks in the options tab for this too)

Code: Select all

{content block="lise_instance" oneline=true label="Type LISE instance name" assign="lise_instance"}{$lise_instance=$lise_instance scope=global}
...

{if $lise_instance == 'instance1'}{LISEInstance1}
{elseif }$lise_instance == 'instance2'}{LISEInstance2}
...
{/if}
Some modules offer custom content blocks which might show to the editors a dropdown box or perhaps radiobuttons. You can use it the same way.
Locked

Return to “The Lounge”