if ($thispage == "david_snyder") echo " <em>Miscellanceous Menu<br />

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
Mads Rasmussen
Forum Members
Forum Members
Posts: 19
Joined: Thu Jan 14, 2010 5:25 pm

if ($thispage == "david_snyder") echo " <em>Miscellanceous Menu<br />

Post by Mads Rasmussen »

I'm trying to create a user defined tag, that will change the menu in the left column - in the right column resides the main menu.
To load the correct left side menu is doable  this way.

But I'm lazy so I tried to more than one value - if ($thispage == "david_snyder | book-by-david-evans")
The code should allow the "|" sign.


global $gCms;
$thispage ="" ;
$thispage = $gCms->variables['page_name'];
if ($thispage == "david_snyder")  echo "  Miscellanceous Menu




elseif  ($thispage == "book-by-david-evans")  echo " Miscellanceous Menu
";

else echo "";

I tried to create a global_content, like:
global $gCms;
$thispage ="" ;
$thispage = $gCms->variables['page_name'];
if ($thispage == "david_snyder")  echo " {global_content name='allebilleder'} ....



elseif  ($thispage == "book-by-david-evans")  echo " Miscellanceous Menu
";

else echo "";

but that wont work.


Anybody with a great idea?

:-)

Mads Rasmussen
fredp
Forum Members
Forum Members
Posts: 218
Joined: Sun Jul 27, 2008 1:36 am
Location: USA

Re: if ($thispage == "david_snyder") echo " <em>Miscellanceous Menu<br />

Post by fredp »

Hi,

I think a look at the wiki examples should get you started:   
    http://wiki.cmsmadesimple.org/index.php/User_Handbook/Admin_Panel/Extensions/User_Defined_Tags#Long_Version

Hope this helps,
Fred P.
Nearly all men can stand adversity, but if you want to test a man's character, give him power.
- Abraham Lincoln
Mads Rasmussen
Forum Members
Forum Members
Posts: 19
Joined: Thu Jan 14, 2010 5:25 pm

Re: if ($thispage == "david_snyder") echo " <em>Miscellanceous Menu<br />

Post by Mads Rasmussen »

I did, Fred P.
And I didn't get any the wiser.

I assume that:

Code: Select all

Passing the page content as a parameter
You can access the page content in a user defined tag by passing it as a parameter:
In your template:
  {content assign=pagecontent}
  {table_of_contents thepagecontent="$pagecontent"}
In your user defined tag named "table_of_contents":
  echo $params['thepagecontent']; // Display page content.
I use this so I can parse to the page content to automatically create a table of contents.
Is a way to go, if modified, but .... ?


I changed:

Code: Select all

if ($thispage == "david_snyder || book-by-david-evans")  echo "  <em>Miscellanceous Menu<br />....
So there are now two "||" which should interpet as "if the first parmeter is meet then ignore the rest".

The editor accept this as valid code, but it doesn't work in preview.

I could of course use:

Code: Select all

global $gCms;
$thispage ="" ;
$thispage = $gCms->variables['page_name'];
if ($thispage == "david_snyder")  echo "  <em>Miscellanceous Menu<br />
   <br />
  </em>
  <ul>
   <li><a href=\"../misc/david_snyder.html\" target=\"_top\">David Snyder</a></li>
   <li><a href=\"../misc/jonathan.html\" target=\"_top\">The Great American Bicycle Wheeze</a></li>
   <li><a href=\"../misc/garageport.html\" target=\"_top\">Garage Port</a></li>
   <li><a href=\"../misc/owners.html\" target=\"_top\">Owners List</a>
   </li>
  </ul>";


elseif  ($thispage == "book-by-david-evans")  echo "<em>Miscellanceous Menu<br />
   <br />
  </em>
  <ul>
   <li><a href=\"../misc/david_snyder.html\" target=\"_top\">David Snyder</a></li>
   <li><a href=\"../misc/jonathan.html\" target=\"_top\">The Great American Bicycle Wheeze</a></li>
   <li><a href=\"../misc/garageport.html\" target=\"_top\">Garage Port</a></li>
   <li><a href=\"../misc/owners.html\" target=\"_top\">Owners List</a>
   </li>
  </ul>";";

else echo "";
but that seems a little bit stupid from a maintainer point of view.
Striving on.
Seems to me that this post is in the catagory?
???

:-)

Mads Rasmussen
fredp
Forum Members
Forum Members
Posts: 218
Joined: Sun Jul 27, 2008 1:36 am
Location: USA

Re: if ($thispage == "david_snyder") echo " <em>Miscellanceous Menu<br />

Post by fredp »

Mads Rasmussen wrote: I did, Fred P.
And I didn't get any the wiser
....
Hi,

Well, at least it appears you learned that user defined tags are not global content blocks.  That's something. :)
I changed:

Code: Select all

if ($thispage == "david_snyder || book-by-david-evans")  echo "  <em>Miscellanceous Menu<br />....
So there are now two "||" which should interpet as "if the first parmeter is meet then ignore the rest".

The editor accept this as valid code, but it doesn't work in preview.
Hmmm.  Unless, I'm misapprehending your meaning, this isn't correct use of the PHP logical OR operator.
Use logical OR operators to join two conditional expressions.
E.g.:
  if ($thispage == "david_snyder" || $thispage == "book-by-david-evans")...

Code: Select all

global $gCms;
$thispage ="" ;
$thispage = $gCms->variables['page_name'];
if ($thispage == "david_snyder")  echo "  <em>Miscellanceous Menu<br />
   <br />
  </em>
  <ul>
   <li><a href="../misc/david_snyder.html" target="_top">David Snyder</a></li>
   <li><a href="../misc/jonathan.html" target="_top">The Great American Bicycle Wheeze</a></li>
   <li><a href="../misc/garageport.html" target="_top">Garage Port</a></li>
   <li><a href="../misc/owners.html" target="_top">Owners List</a>
...
but that seems a little bit stupid from a maintainer point of view.
...
Indeed! Hard-coding menus into UDTs isn't scalable and is,  in my experience, typically unnecessary.  If you put your content into CMSMS pages, then CMSMS knows your page hierarchy. That means you can use the menu manager (module) to generate all kinds of menus (e.g., horizontal menus, vertical menus, footer menus, etc.) using menu templates and your page hierarchy, stored in the database. Have you looked into using the menu manager?

If not, you might create a test installation of CMSMS and include the optional content and templates. There are multiple examples of menu manager generated menus in there. You can modify a template or make your own to get almost any result you desire.  

The wiki docs have menu manager examples and tutorials, as well:
http://wiki.cmsmadesimple.org/index.php/User_Handbook/Admin_Panel/Layout/Menu_Manager#About_the_Menu_Manager

Also search the forums for questions about using the menu manager.  For example:
http://forum.cmsmadesimple.org/index.php/topic,12608.msg62524.html#msg62524

Hope this helps,
Fred P.

EDIT: typo fixed
Last edited by fredp on Sat Feb 13, 2010 1:28 am, edited 1 time in total.
Nearly all men can stand adversity, but if you want to test a man's character, give him power.
- Abraham Lincoln
Post Reply

Return to “Developers Discussion”