Page 1 of 1

[SOLVED] if statement based on cgsimplesmarty

Posted: Mon Nov 18, 2013 8:02 pm
by turpentyne
Calguy gave me a good tip on manipulating content in the template - only problem is, this is the deepest I've had to go in coding for CMSMS, so I'm in new territory.

I'm trying to understand syntax for the cgsimplesmarty plugin, what I want is for a block to appear if the user is in a specific page, or any of its children. I've gotten halfway there, I think, but I'm not sure I understand the aliases and syntax correctly enough to bring it on home... (and I think I stumbled on a glitch between getting title or alias)

Here's what I've got so far:

Code: Select all


{$cgsimple->get_page_title('Starting out',$assign)} <br/>
           {$assign}
// not fulling understanding how to set the variable and then use it
            {$cgsimple->get_page_title($cgsimple->get_parent_alias(), 'maintitle')} 
           <br/>
               {$maintitle2} 
               here? {$the_current_page} <br/>
               {if $maintitle == "Starting out"}
                 ..  {content block = "Sidebar"} ..
                  // this works great for the subpages, but not the parent.
               {/if}

Regarding the glitch (and reason I'm using page titles: when I tried to do get_page_alias, my page wouldn't save for unknown reasons. I don't know if it has something to do with aceEditor that I just installed, or not.

Re: if statement based on cgsimplesmarty

Posted: Mon Nov 18, 2013 8:28 pm
by turpentyne
Ok... made a little progress, by changing the first two lines - cleared out 'starting out' (and fixing variable name, now that I understand a little better):

Code: Select all

{$cgsimple->get_page_title('','parentvariable')} <br/>
{$parentvariable} // echoed for testing
So now, I just need to figure out how to add in my "or" statement to get this wrapped up.

Re: if statement based on cgsimplesmarty

Posted: Mon Nov 18, 2013 8:41 pm
by turpentyne
Waiiiiit... could it be this simple? I think I got it fixed. If anybody has any thoughts on whether this is fine, or there's a better way, or issues I need to be aware of, let me know. But here's what I ended up with in my template to hide/show a second content block, if they're in a specific content page and any of its subpages.

Code: Select all

{$cgsimple->get_page_title('','ifparent')}        {$cgsimple->get_page_title($cgsimple->get_parent_alias(), 'maintitle')} 
{if ($maintitle == "Starting out") or ($parenttitle == "Starting out")}
       Sidebar<br/>
      {content block = "Sidebar"} 
{/if}            

Re: if statement based on cgsimplesmarty

Posted: Mon Nov 18, 2013 9:20 pm
by calguy1000
given a page structure like this:

1. Page A (alias = "page-a")
2. Page B (alias = "page-b")
2.1 Page B-1 (alias = "page-b-1");
2.1.1 Page B-1-1 (alias = "page-b-1-1")
2.1.2 Page B-1-2 (alias = "page-b-1-2")
2.2 Page B-2 (alias = "page-b-2")
3. Page C (alias = "page-c")

And you have a global content block called 'mygcb' that you want displayed on "page-b" and everything below it.

I'd use syntax like this:

Code: Select all

{cgsimple::get_root_alias('','root_alias')}
{if $root_alias == 'page-b' or $page_alias == 'page-b'}
  {global_content name="mygcb"}
{/if}