Page 1 of 1
[Solved] Variable in Module Parameter
Posted: Tue May 24, 2011 11:18 am
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'}
Re: Variable in Module Parameter
Posted: Tue May 24, 2011 11:27 am
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
Re: Variable in Module Parameter
Posted: Tue May 24, 2011 11:33 am
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?
Re: Variable in Module Parameter
Posted: Tue May 24, 2011 11:39 am
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?
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>
Re: Variable in Module Parameter
Posted: Tue May 24, 2011 11:51 am
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
Re: Variable in Module Parameter
Posted: Tue May 24, 2011 12:04 pm
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}
Re: Variable in Module Parameter
Posted: Tue May 24, 2011 1:06 pm
by faxtion
Jos,
Thanks alot, works perfectly now..