Page 1 of 1
Show modules in Sidebar depending on content ID or alias
Posted: Sat Jan 02, 2010 11:58 pm
by docman
Hi, I wonder if it was possible to show modules in Sidebar depending on content's ID or alias? It would be really nice, and I am sure it would follow the concept of FEU smarty coding, but I am not that sure or experienced.
Thanks for your help in advance!
Re: Show modules in Sidebar depending on content ID or alias
Posted: Wed Jan 06, 2010 3:59 am
by jmcgin51
this would have nothing to do with FrontEndUsers, BTW.
to expand on Dr.CSS's post...
something like
{if $page_alias == 'homepage'}
{news}
{elseif $page_alias == 'page2'}
{Uploads}
{elseif $page_alias == 'login'}
{FrontEndUsers}
{/if}
Re: Show modules in Sidebar depending on content ID or alias
Posted: Wed Jan 06, 2010 10:40 pm
by docman
Thanks.
May I follow up a bit. Can one filter for pages that do have content other than public, like for registered users (feu) and their groups?
Re: Show modules in Sidebar depending on content ID or alias
Posted: Wed Jan 06, 2010 11:00 pm
by jmcgin51
off the top of my head, an easy way would be to use the additional page attributes
(I can't remember the exact syntax for those attributes, but it would be something like this)
{if $extra1 == 'public'}
{news}
{elseif $extra1 == 'private'}
{Uploads}
{elseif $extra1 == ''}
{FrontEndUsers}
{/if}
You would simply add the appropriate keyword into the Extra 1 attribute field when creating the page. If the page has only public content, add 'public' to the Extra1. If the page has private content (protected by FEU/CC), add 'private'. Etc...
This would allow for quick and simple implementations, but would not work for more complex logic. There are probably several other ways to accomplish the same thing...
Re: Show modules in Sidebar depending on content ID or alias
Posted: Thu Jan 07, 2010 5:32 pm
by docman
Any hints as to where can I find out the proper format of the commands your were giving?
The you were giving did not work.
I tried printing out the content of $extra1 using this
It did not worked either, because the result was "1" irrespective if I printed out $extra1, $extra2, etc ($extra1 was assigned to "r" in the admin panel of the page). I am not certain if the print command is proper either.
Are we talking here Smarty formalism or PHP?
Do you have a suggestion to filter for a News Items of a given Category?
Thanks again.
Re: Show modules in Sidebar depending on content ID or alias
Posted: Thu Jan 07, 2010 8:46 pm
by Peciura
For content extra field try
Code: Select all
{if $content_obj->GetPropertyValue('extra1')=='public'}
public content
{elseif $content_obj->GetPropertyValue('extra1')=='private'}
private content
{else}
default content
{/if}
P.S. don't forget to use "{get_template_vats}" first.
Re: Show modules in Sidebar depending on content ID or alias
Posted: Thu Jan 07, 2010 9:24 pm
by docman
This is that youe meant saying "use {get_template_vars} first"?
Code: Select all
{get_template_vars}
{if $content_obj->GetPropertyValue('extra1')=='public'}
public content
{elseif $content_obj->GetPropertyValue('extra1')=='private'}
private content
{else}
{/if}
This will include a large table with the template variable in the output. Incidentally, I looked for "$extra1" but could not find. I also printed out the content of $content_obj using {$content_obj|print_r}. I did find the label "extra1" but could not verify its content.
Hence my questions:
1. does $extra1 hold the value that I assude it does?
2. is this value being passed to the output template of the search module where I am testing this filtering you suggest?
Let me summarize and a bit rephrase my aim:
1. I use FEUs.
2. I created some restricted content for them in TWO places
- in Content Pages inserted into content blocks for Registered Users
- in News items into a category 'Restricted'
3. Now, when I use Search without any filtering in its Output Template, a search term containing some text that could also be found in these restricted content would result in listing those contents, that I obviously want to avoid
4. Hence the need for filtering by code (smarty) placed into the output template
5. One way of achieving this - as you suggested - is by using an Extra Page Attribute
6. One thus have to filter on the content of this Extra Page Attribute in a two-teared manner
- once for the registered content
- once for the news item in the 'Restricted' category
7. Obviously, using Extra Page Attributes would only work for the restricted content but not for the news item.
Unfortunately, filtering on Extra1 has not succeeded (see above).
Thank you for your continuing help.
Re: Show modules in Sidebar depending on content ID or alias
Posted: Fri Jan 08, 2010 11:10 am
by Peciura
I looked for "$extra1" but could not find.
Variable "extra1" does not exist in your template. That is the point - to look for valid template variables first.
Search module have parameter
passthru_*="null" - Pass named parameters down to specified modules. The format of each of these parameters is: "passtru_MODULENAME_PARAMNAME='value'" i.e.: passthru_News_detailpage='newsdetails'"
Lets use it
Code: Select all
{search passthru_News_category='restricted*'}
Structure of one search result looks like this
Code: Select all
object(stdClass)#456 (7) {
["url"]=> string(117) "http://www...."
["urltxt"]=> string(26) "Title..."
["title"]=> string(9) "News..."
["intweight"]=> int(3)
["module"]=> string(4) "News"
["modulerecord"]=> string(3) "300"
["weight"]=> int(100)
}
Pay attention to properties "weight" and "intweight". IMO record with "wheight"==100 meets all search conditions (search string, News category, ...). You can not to show some records from news module with low weight.
is this value being passed to the output template of the search module where I am testing this filtering you suggest?
In general template variables are retained if "page_id" is the same as "returnid" in URL.
Re: Show modules in Sidebar depending on content ID or alias
Posted: Fri Jan 08, 2010 2:27 pm
by docman
Please find my followup questions embedded into your post!
Thanks a lot!
I looked for "$extra1" but could not find.
Variable "extra1" does not exist in your template. That is the point - to look for valid template variables first.
docman: thanks, this is that I suspected.
Search module have parameter
passthru_*="null" - Pass named parameters down to specified modules. The format of each of these parameters is: "passtru_MODULENAME_PARAMNAME='value'" i.e.: passthru_News_detailpage='newsdetails'"
docman:
- where should this command go? I have two templates: one is that I would call the "main", the other is the "result template of the search module". The seconds one may just be inserted into the main one as soon as the {search} tag is executed, but I really do not know for sure.
Lets use it
Code: Select all
{search passthru_News_category='restricted*'}
docman:
- what would be the command to pass the value of extra1? Something like this?
Code: Select all
{search passthru_exra1='restricted*'}
docman:
- again, where would the following code of yours be inserted?
Structure of one search result looks like this
Code: Select all
object(stdClass)#456 (7) {
["url"]=> string(117) "http://www...."
["urltxt"]=> string(26) "Title..."
["title"]=> string(9) "News..."
["intweight"]=> int(3)
["module"]=> string(4) "News"
["modulerecord"]=> string(3) "300"
["weight"]=> int(100)
}
Pay attention to properties "weight" and "intweight". IMO record with "wheight"==100 meets all search conditions (search string, News category, ...). You can not to show some records from news module with low weight.
is this value being passed to the output template of the search module where I am testing this filtering you suggest?
docman:
- I am afraid I do not understand the following. Could you elaborate on it a bit?
[/quote]In general template variables are retained if "page_id" is the same as "returnid" in URL.
Re: Show modules in Sidebar depending on content ID or alias
Posted: Sun Jan 10, 2010 1:05 am
by Peciura
Basic steps to filter out restricted news are:
1. In news extra field mark restricted record
2. Set summary template not to show restricted articles
Code: Select all
{if empty($entry->extra)||($ccuser->loggedin()&&$ccuser->memberof($entry->extra))}
show summary
{/if}
3. Also hide content of restricted articles in detail template
4. (optional) When calling search module also pass name of news summary template to search results
Code: Select all
{search passthru_News_summarytemplate='summary_template'}
a. There is no need to specify template if it is default one. Also you can skip it if you will specify it on step "5"
5. Use UDT to call articles by articleid in summary mode (by default article id is valid in detail mode only)
EDIT: parameter "ids" comma separated list of news article ids.
Code: Select all
{if $entry->module=='News'}
{news_ids ids=$entry->modulerecord summarytemplate='template_filter'}
{/if}
Re: Show modules in Sidebar depending on content ID or alias
Posted: Sun Jan 10, 2010 1:19 am
by docman
Thanks for your reply. Please specify where the code segments you suggest would have toi be inserted. I am aware of two possible sites such as my "main" template and the summary template of the News module.
Thanks a lot.
Re: Show modules in Sidebar depending on content ID or alias
Posted: Tue Jan 12, 2010 2:26 pm
by Peciura
Please specify where the code segments you suggest would have toi be inserted
step 2 goes to news summary template (created specially for search results, titlelinks only)
step 3 - news detail templates (you want to be sure content visible to authorized vistors)
step 4 - test page first, later to main page template
step 5 - search result template
Re: Show modules in Sidebar depending on content ID or alias
Posted: Tue Jan 12, 2010 7:21 pm
by docman
Peciura wrote:
Please specify where the code segments you suggest would have toi be inserted
step 2 goes to news summary template (created specially for search results, titlelinks only)
step 3 - news detail templates (you want to be sure content visible to authorized vistors)
step 4 - test page first, later to main page template
step 5 - search result template
Thanks. I have to admit, it is still not working. Certainly, because I am haviong gaps in terms of the formalism and concepts used in your code.
Hence, my questions:
Is my interpretation of this code proper?
Code: Select all
{if empty($entry->extra)||($ccuser->loggedin()&&$ccuser->memberof($entry->extra))}
show summary
{/if}
- if updated content of $entry is NULL (that is extra is empty in the news item) OR if user is logged in AND he/she is member of group as specified in extra
- THEN show news using the summary template
My questions:
1. I wanted to verify if extra has the value in the summary template that I assigned to it in the news item page ("restricted"). Hence in the above code (for step2) I inserted "{$extra|print_r} to print its value. Its value is always "1".
2. I am uncertain if the value of extra is passed on from the news item page to the summary or for that matter the detailed templates. What is the rule and code that applies to transferring values of parameters?
3. If this is the code for checking on the status of the user being logged in
"{if $ccuser->loggedin()} ...{/if}
what would be the conditional testing for a user being NOT logged in?
4. Is this construct correct?
Code: Select all
{if $entry->module=='News' category!='Private'}
...
{/if}
For me it did not work. The idea to use it in the search results template would be to check if the item is coming from the News module and if its category is not Private; then the result could be displayed. Is the values of category passed to the search template?
5. Where can I learn more on the followings with a focus on their implementation in CMSMS?
- passing parameters values in between templates
- passing parameters values in between content extra1, etc., and templates
- passing parameters values in between news extra and templates
- conditional testing on page attributes
- definitions of CMSMS tags
Many thanks for your help.
Re: Show modules in Sidebar depending on content ID or alias
Posted: Wed Jan 13, 2010 10:42 am
by Peciura
Is my interpretation of this code proper?
Code:
{if empty($entry->extra)||($ccuser->loggedin()&&$ccuser->memberof($entry->extra))}
show summary
{/if}
- if updated content of $entry is NULL (that is extra is empty in the news item) OR if user is logged in AND he/she is member of group as specified in extra
- THEN show news using the summary template
Yes.
1. I wanted to verify if extra has the value in the summary template that I assigned to it in the news item page ("restricted"). Hence in the above code (for step2) I inserted "{$extra|print_r} to print its value. Its value is always "1".
a. If you simply want to restrict article in step 2 change to simple one
Code: Select all
{if empty($entry->extra)||($ccuser->loggedin()&&$entry->extra=='restricted'))}
show summary
{/if}
b. To debug like
or i like {var_dump var=$entry}. The link to UDT "var_dump" is at my signature.
2. I am uncertain if the value of extra is passed on from the news item page to the summary or for that matter the detailed templates. What is the rule and code that applies to transferring values of parameters?
Value of extra field is passed to summary.
{var_dump var=$entry} output is
Code: Select all
object(stdClass)#441 (23) {
["author_id"]=>
string(1) "1"
["author"]=>
string(7) "admin"
["authorname"]=>
string(17) "..."
["id"]=>
string(3) "359"
["title"]=>
string(40) "Blah"
["content"]=>
string(2139) "..."
["summary"]=>
string(692) "..."
["postdate"]=>
string(19) "2009-10-16 13:45:54"
["extra"]=>
string(2) "53"
["startdate"]=>
string(19) "2009-10-16 13:45:54"
["enddate"]=>
NULL
["create_date"]=>
string(19) "2009-10-16 13:56:05"
["modified_date"]=>
string(19) "2009-12-19 00:44:08"
["category"]=>
string(23) "..."
["fieldsbyname"]=>
array(0) {
}
["fields"]=>
array(0) {
}
["file_location"]=>
string(43) "http://www.test..../uploads/news/id359"
["link"]=>
string(167) "http://www.test..."
["titlelink"]=>
string(222) "BLAH"
["morelink"]=>
string(189) "More"
["moreurl"]=>
string(167) "http://www.test..."
["printlink"]=>
string(199) "Print"
["printurl"]=>
string(174) "http://www.test..."
}
3. If this is the code for checking on the status of the user being logged in
"{if $ccuser->loggedin()} ...{/if}
Code: Select all
{if !$ccuser->loggedin()} ...{/if}
or
Code: Select all
{if empty($ccuser->loggedin())} ...{/if}
4. Is this construct correct?
Code:
{if $entry->module=='News' category!='Private'}
...
{/if}
For me it did not work. The idea to use it in the search results template would be to check if the item is coming from the News module and if its category is not Private; then the result could be displayed. Is the values of category passed to the search template?
a. You missed logical "AND". Should be
Code: Select all
{if $entry->module=='News'&&category!='Private'}
...
{/if}
b. No, value of category is not passed to search module.
Structure of one search result looks like this
Code:
object(stdClass)#456 (7) {
["url"]=> string(117) "
http://www...."
["urltxt"]=> string(26) "Title..."
["title"]=> string(9) "News..."
["intweight"]=> int(3)
["module"]=> string(4) "News"
["modulerecord"]=> string(3) "300"
["weight"]=> int(100)
}
5. Where can I learn more on the followings with a focus on their implementation in CMSMS?
passing parameters values in between templates
I usually use global php variables $_GET, $_POST, $_COOKIE . Smarty can access them to ({$smarty} reserved variable)
http://www.smarty.net/manual/en/language.variables.smarty.php
- passing parameters values in between content extra1, etc., and templates
- passing parameters values in between news extra and templates
- conditional testing on page attributes
- definitions of CMSMS tags
a. I recommend reading all blog
http://calguy1000.com/blog.html, you can start with
http://calguy1000.com/Blogs/4/60/the-we ... dness.html
b. Smarty page
http://www.smarty.net/manual/en/
start with "Variable Modifiers", "Built-in Functions".
c. Extensions » Tags

d. Read my post about relationship between php functions and smarty variable modifiers
http://forum.cmsmadesimple.org/index.ph ... #msg190202
No probs.