[Solved] Variable in Module Parameter

Have a question or a suggestion about a 3rd party addon module or plugin?
Let us know here.
Post Reply
faxtion
Forum Members
Forum Members
Posts: 26
Joined: Tue Sep 14, 2010 10:38 am
Location: Dumfries

[Solved] Variable in Module Parameter

Post by faxtion »

Is it possible to use a variable in a modules parameter?

I am trying to do the following:

Pass the extra page attribute of a page through a modules category parameter

Code: Select all

{cms_module module='module' template='page' category='{page_attr key="extra2"}'}
But it's not working, I have tried using the capture method to capture the page_attr but for some reason can not get the module to recognize the variable. I know the capture is working right as I did a dump of variable before and it gave me the word

Code: Select all

{capture assign="pex1"}
{page_attr key="extra1"}
{/capture}

{cms_module module='module' template='page' category='$pex1'}

Last edited by faxtion on Tue May 24, 2011 1:06 pm, edited 1 time in total.
Jos
Support Guru
Support Guru
Posts: 4019
Joined: Wed Sep 05, 2007 8:03 pm
Location: The Netherlands

Re: Variable in Module Parameter

Post by Jos »

Code: Select all

{capture assign="pex1"}
{page_attr key="extra1"}
{/capture}

{cms_module module='module' template='page' category=$pex1}
Just leaving out the quotes around the variable will do the job
faxtion
Forum Members
Forum Members
Posts: 26
Joined: Tue Sep 14, 2010 10:38 am
Location: Dumfries

Re: Variable in Module Parameter

Post by faxtion »

It seems to be not passing the text through to the category parameter.

I have the following in my template

Code: Select all

{capture assign="pex1"}
{page_attr key="extra1"}
{/capture}

{cms_module module='listitdownloads' template='page' category=$pex1}
It will output the template, with no content, but if I do

Code: Select all

{cms_module module='listitdownloads' template='page' category='young'}
It works..

Could it possibly be something to do with the module?
Jos
Support Guru
Support Guru
Posts: 4019
Joined: Wed Sep 05, 2007 8:03 pm
Location: The Netherlands

Re: Variable in Module Parameter

Post by Jos »

If the value in the extra1 field = "young" it should give you the same result.
Maybe it helps if you use no quotes in the capture statement?

Code: Select all

{capture assign=pex1}
You can check the value of $pex1 by adding this code to your template:

Code: Select all

<p>debug:<br />
page_atrr: {page_attr key="extra1"}<br />
$pex1: {$pex1}</p>
faxtion
Forum Members
Forum Members
Posts: 26
Joined: Tue Sep 14, 2010 10:38 am
Location: Dumfries

Re: Variable in Module Parameter

Post by faxtion »

Jos,
Thanks for your help, but for some strange reason the category parameter is not seeing the variable. I have the following in my template:

Code: Select all

{capture assign="pex1"}
{page_attr key="extra1"}
{/capture}

<p>debug:<br />
page_atrr: {page_attr key="extra1"}<br />
$pex1: {$pex1}</p>

{cms_module module='listitdownloads' template='page' category=$pex1}

{cms_module module='listitdownloads' template='page' category='young'}
The first module template tag will output the template for the module but not fetch the category info, but the second works perfect. Both page_attr and $pex1 in debug <p> show "young"

Very Strange, and mind boggling
Jos
Support Guru
Support Guru
Posts: 4019
Joined: Wed Sep 05, 2007 8:03 pm
Location: The Netherlands

Re: Variable in Module Parameter

Post by Jos »

$pex1 seems to contain an extra space or page return. Capture it in one line like this:

Code: Select all

{capture assign=pex1}{page_attr key="extra1"}{/capture}
faxtion
Forum Members
Forum Members
Posts: 26
Joined: Tue Sep 14, 2010 10:38 am
Location: Dumfries

Re: Variable in Module Parameter

Post by faxtion »

Jos,

Thanks alot, works perfectly now..
Post Reply

Return to “Modules/Add-Ons”