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

Talk about writing modules and plugins for CMS Made Simple, or about specific core functionality. This board is for PHP programmers that are contributing to CMSMS not for site developers
Post Reply
AlanY

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

Post 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.
Last edited by AlanY on Sun Jul 19, 2009 9:25 pm, edited 1 time in total.
atired
Forum Members
Forum Members
Posts: 26
Joined: Mon May 21, 2007 8:37 pm

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

Post by atired »

I have a similar problem. Have you solved this? If so, how?
jmcgin51
Power Poster
Power Poster
Posts: 1899
Joined: Mon Jun 12, 2006 9:02 pm

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

Post 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}
Dee
Power Poster
Power Poster
Posts: 1197
Joined: Sun Mar 19, 2006 8:46 pm
Location: the Netherlands

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

Post 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
viebig

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

Post 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}
atired
Forum Members
Forum Members
Posts: 26
Joined: Mon May 21, 2007 8:37 pm

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

Post 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...
Dee
Power Poster
Power Poster
Posts: 1197
Joined: Sun Mar 19, 2006 8:46 pm
Location: the Netherlands

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

Post 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
Last edited by Anonymous on Fri Jul 17, 2009 2:31 am, edited 1 time in total.
viebig

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

Post by viebig »

UDT´s are for PHP code only

Templates, pages and content blocks are SMARTY and html

Regards

G
atired
Forum Members
Forum Members
Posts: 26
Joined: Mon May 21, 2007 8:37 pm

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

Post 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?
Dee
Power Poster
Power Poster
Posts: 1197
Joined: Sun Mar 19, 2006 8:46 pm
Location: the Netherlands

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

Post 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
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm
Location: Fernie British Columbia, Canada

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

Post by calguy1000 »

{$page_alias}

nuf said.
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
Dee
Power Poster
Power Poster
Posts: 1197
Joined: Sun Mar 19, 2006 8:46 pm
Location: the Netherlands

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

Post 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
atired
Forum Members
Forum Members
Posts: 26
Joined: Mon May 21, 2007 8:37 pm

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

Post 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?
jmcgin51
Power Poster
Power Poster
Posts: 1899
Joined: Mon Jun 12, 2006 9:02 pm

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

Post by jmcgin51 »

Unless you started the thread, you can't edit the original post title, which is where [SOLVED] needs to go.
Post Reply

Return to “Developers Discussion”