Page 1 of 1

[solved] Calling a module within a UDT or vice-versa

Posted: Tue May 19, 2009 8:21 pm
by AlanY
I'm trying to use a UDT to grab the URL GET variables, and use them inside a module call.

So in effect I want something like this in a page:

{news start={udt_getstart} number={udt_getnumber} }

This doesn't work as the closing bracket for "udt_getstart" will close the News module call and the rest will be output as-is on the page.  Is there another way to grab the page's URL parameters and use them in a module call?

Another thing I tried was grabbing the GET variables in a UDT, and then echo-ing out the module call to the page:
--
$start = $_GET['start'];
$number = $_GET['number'];

print '{news start='.$start.' number='.$number.' }';
--

But that just printed out a string and didn't actually call the module....

Any help would be appreciated.

Re: Calling a module within a UDT or vice-versa

Posted: Thu Jul 16, 2009 3:59 pm
by atired
I have a similar problem. Have you solved this? If so, how?

Re: Calling a module within a UDT or vice-versa

Posted: Thu Jul 16, 2009 4:16 pm
by jmcgin51
I think you're on the right track with this:
Another thing I tried was grabbing the GET variables in a UDT, and then echo-ing out the module call to the page:
--
$start = $_GET['start'];
$number = $_GET['number'];

print '{news start='.$start.' number='.$number.' }';
But don't print it to the page.  Try:

{news start=$start number=$number}

Re: Calling a module within a UDT or vice-versa

Posted: Thu Jul 16, 2009 8:44 pm
by Dee
There are many solutions to this, among them is using Smarty's {assign} or {capture} functions or even accessing the news module directly (available in the global $gCms->modules['News']['object']).
Easiest would be to use the $_GET variables, available in the$smarty.get property:

Code: Select all

{news start=$smarty.get.start number=$smarty.get.number}
Kind regards,
D

Re: Calling a module within a UDT or vice-versa

Posted: Thu Jul 16, 2009 11:10 pm
by viebig
read more about smarty capture

you can have a udt that generates anything like {getdata}

then you can use it like:

Code: Select all

{capture assign="getdata"}{getdata}{/capture}
{module var=$getdata}

Re: Calling a module within a UDT or vice-versa

Posted: Fri Jul 17, 2009 12:28 am
by atired
I don't really understand any of this, as i'm just a designer. My UDT looks like this so far:

global $gCms;
$thispage = $gCms->variables['page_name'];
if ($thispage == "portfolio") 
echo "Portfolio:"
{cms_module module='CGBlog' action='browsecat' summarypage='det_Portfolio'}
echo "";
elseif  ($thispage == "divagacoes")
echo "Divagacoes:"
{cms_module module='news' action='browsecat' detailpage='det_Divagacoes'}
echo "";
elseif  ($thispage == "contato") echo "etc";
else echo "default text";

But I get an error in line 5. The workaround is having a different template for each page, but I wanted to do this right...

Re: Calling a module within a UDT or vice-versa

Posted: Fri Jul 17, 2009 2:07 am
by Dee
atired wrote: I don't really understand any of this, as i'm just a designer. My UDT looks like this so far:

global $gCms;
$thispage = $gCms->variables['page_name'];
if ($thispage == "portfolio")  
echo "Portfolio:"
{cms_module module='CGBlog' action='browsecat' summarypage='det_Portfolio'}
echo "";
elseif  ($thispage == "divagacoes")
echo "Divagacoes:"
{cms_module module='news' action='browsecat' detailpage='det_Divagacoes'}
echo "";
elseif  ($thispage == "contato") echo "etc";
else echo "default text";

But I get an error in line 5. The workaround is having a different template for each page, but I wanted to do this right...
Try this in your template:

Code: Select all

<div id='$gCms->parameters.page_name'>
<h4>{$gCms->parameters.page_name|ucfirst}:</h4>
{cms_module module='CGBlog' action='browsecat' summarypage="det_$gCms->parameters.page_name|ucfirst"}
</div>
If you need something page specific in the template you can use Smarty logic:

Code: Select all

{if $gCms->parameters.page_name == 'portfolio'}
* this is only displayed on the portfolio page *
{/if}
Kind regards,
D

Re: Calling a module within a UDT or vice-versa

Posted: Fri Jul 17, 2009 4:29 am
by viebig
UDT´s are for PHP code only

Templates, pages and content blocks are SMARTY and html

Regards

G

Re: Calling a module within a UDT or vice-versa

Posted: Fri Jul 17, 2009 4:59 am
by atired
Ok, but smarty is waaay out of my league.

Dee pointed me the way to go, I think. But I tried placing this in my template, and nothing is displayed:

{if $gCms->parameters.page_name == 'portfolio'}
* this is only displayed on the portfolio page *
{elseif  $gCms->parameters.page_name == 'divagacoes'}
*page specific content*
{/if}

Is page_name the page alias?

Re: Calling a module within a UDT or vice-versa

Posted: Fri Jul 17, 2009 8:55 pm
by Dee
If you're a designer and not a programmer, Smarty should be more in your league than PHP code, although it has similar syntax and does need some getting used to. Luckily it has extended documentation.

page_name is the page alias indeed, it is displayed when you just use

Code: Select all

{$gCms->parameters.page_name}
The code you used should display "* this is only displayed on the portfolio page *" on the portfolio page and "* page specific content*" on the page with alias 'divagacoes':

Code: Select all

{if $gCms->parameters.page_name == 'portfolio'}
* this is only displayed on the portfolio page *
{elseif  $gCms->parameters.page_name == 'divagacoes'}
*page specific content*
{/if}
If you're using it in a template I don't see why this wouldn't work. If you're trying to insert it on a page you'll have to turn off WYSIWYG because TinyMCE will change the -> into ->

Kind regards,
D

Re: Calling a module within a UDT or vice-versa

Posted: Fri Jul 17, 2009 8:56 pm
by calguy1000
{$page_alias}

nuf said.

Re: Calling a module within a UDT or vice-versa

Posted: Fri Jul 17, 2009 9:19 pm
by Dee
calguy1000 wrote: {$page_alias}

nuf said.
Thanks calguy,

Some testing revealed $gCms->parameters is not always assigned.
I would have used {$gCms->variables.pageinfo->content_alias}, which does seem to be always available, but apparently a convenience variable {$page_alias} is assigned to Smarty as well.

Maybe some documentation about the variables assigned to Smarty would be a good thing... although it may have the devs realize too much is assigned right now. For example, I think not many users realize that anyone with rights to edit a page or template has access to the database user and password and thus can do any page operation he/she wants...

Kind regards,
D

Re: Calling a module within a UDT or vice-versa

Posted: Sat Jul 18, 2009 12:35 am
by atired
When I replaced {if $gCms->parameters.page_name == 'portfolio'} with {if $page_alias == 'portfolio'} it worked. Thank you all.

Now I have a forum related question: I didn"t start this thread but it seems yhe person who did has abandoned it. Should I place the [SOLVED] tag?

Re: Calling a module within a UDT or vice-versa

Posted: Sat Jul 18, 2009 1:46 am
by jmcgin51
Unless you started the thread, you can't edit the original post title, which is where [SOLVED] needs to go.