How to do module calls to a page over query string from links in content?

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
neuroboy
Forum Members
Forum Members
Posts: 13
Joined: Sun Dec 02, 2007 4:10 am

How to do module calls to a page over query string from links in content?

Post by neuroboy »

(Apologies if posting in wrong forum!)

I've put the subject of this post as "How to do module calls to a page over query string from links in content?", but I'm not sure if this actually what I might need to do.

To explain...

I have setup a site that uses the News module for news items, events listings and a resource directory of short information articles, files and links to external websites. There are 3 main categories each with 5 sub-categories.

Now, I started to produce an individual page for each of the 3 main categories, with some introductory text for each and the relevant  module call in the content, e.g. :

Code: Select all

{news category="Resources*" number="10"}
I realised I'd probably need to create a page for each individual sub-category as well, making 15 pages.

But I then remembered that users would need to view all resources by date or in alphabetical order, also giving them the choice to view the categories either by browsing 10 on a page with summaries, or as one big long simplified list (using custom templates).

I thought that this would have to be done by creating 4 individual pages for each of the 15 sub categories each with a heading, links to the pages with the other options, and module calls like the following:

Code: Select all

{news category="Careers Resources" sortby="news_title" sortasc="true" summarytemplate="withsummary" number="10"}
{news category="Careers Resources" sortby="news_title" sortasc="true" summarytemplate="simplelist"}

It was when I started thinking that users would probably also like to be able to view all options in reverse order (Z to A and oldest article first) that I realised that this whole thing was going to get very time-consuming and unwieldy, and that there must be a more elegant way of doing it.

To me, a logical solution is a single page that can handle module calls to all categories and sub-categories and viewing options, passed on from links within itself using query strings. Or at the very least a page for each of the 3 main categories that can do the same. This is something I could do with basic PHP, but I can't work out how to mix smarty module calls and PHP like that within the CMS content.

I'm not a complete beginner - I've set up 4 sites with CMSMS, I know the basics of PHP, am getting my head round smarty and have written my own UDTs, but I think I've fried my brain today as I'm stumped as to a way of proceeding.

Perhaps I need to write a UDT that creates the links? Or a page template that can process the code? Or both? My head hurts!

Anyone care to help? Thanks!
Last edited by neuroboy on Sat Jan 10, 2009 1:31 am, edited 1 time in total.
User avatar
plger
Forum Members
Forum Members
Posts: 196
Joined: Wed Oct 15, 2008 10:38 am

Re: How to do module calls to a page over query string from links in content?

Post by plger »

If I understood you well, I think I might have a suggestion.

Indeed I believe you should create only one page and let the module do its stuff.
For categories, instead of doing the links yourself, using the news module's action to display a list of categories (browsecat paramater I think) should do the trick, as it outputs links not to pages but to module actions (which will replace the page content).

This being said, the problem remains for all those neat little functions you are talking about.
It has been suggested that all modules should include a "link" action, a tag which would not display the module content, but only a link to it. Now to my knowledge, the News module has no such action. But it would be pretty easy to create one :

Create a file in the module's folder and name it action.link.php
Put the following content :

Code: Select all

<?php
	if (!isset($gCms)) exit;
	if(isset($params["linkto"])){
		echo $this->CreateLink($id,$params['linkto'],$returnid,$contents='link',$params,'',true);
	}
?>
So we've just added an action that creates a link to another action. It should be used with a tag like :

Code: Select all

{news action="link" linkto="default" sortasc="true" category="mycategory"}
This would output a link (a href, to be precise, so you can use it to make arrow links and stuff) to the equivalent of

Code: Select all

{news action="default" sortasc="true" category="mycategory"}
You just pass whatever parameter you want.

Now, this should be working, but the problem is that we've added a new parameter ( linkto ), and the news module restricts the possible parameters. So you'd have either to comment the line $this->RestrictUnknownParams();  in News.module.php, or to register our parameter. To do the latter, simple add those lines to the SetParameters() function of News.module.php :

Code: Select all

$this->CreateParameter('linkto', 'default', 'Used with action "link", to define the action to which we want to link.');
Now, to be honest I haven't tested any of that, but I believe it should work :)
(Hope it's what you were looking for)

Pierre-Luc
User avatar
plger
Forum Members
Forum Members
Posts: 196
Joined: Wed Oct 15, 2008 10:38 am

Re: How to do module calls to a page over query string from links in content?

Post by plger »

Hello again neuroboy,
As it has been a while, I was wondering if this (replacing pages with module links) had helped with your problem. If anything wasn't clear enough (I realize I didn't explain some details of the application) or if it doesn't answer your question, let me know.
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm
Location: Fernie British Columbia, Canada

Re: How to do module calls to a page over query string from links in content?

Post by calguy1000 »

See CGSimpleSmarty and the {module_action_link} plugin.
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.
Post Reply

Return to “Developers Discussion”