TAL conditional statement - newbie question
Hi ALL: I am just starting to learn zope/plone and templates. I have a portal that uses plone templets and skins. My question is how I can HREF conditionally using TAL syntax. I defined a macro in my plone template file (*.pt file) like this: <p metal:define-macro="news_link"> <-- Just link the News Archive --> <a href="/my.portal.edu/news">News Archive </a> </p> But, as this macro is called form the the right_slots via the "properties Tab" for the CFM site object (eg. here/news_slot/macros/news_link), this link will display in all the pages in the right slot. But I don't want this link to be displayed when I am actually in that page itself (my.portal.edu/news). Note: "news" is a CMF portal action called by action "string: $portal_url/news" So the ideal code will be: If the current URL != $portal_url/news then <a href="/my.portal.edu/news">News Archive </a> else do nothing Here are my questions: 1. How to get the ID of an object (say "news" in this case so that I can conditionally suppress the HREF, so that if I am in the $portal_url/news page, the link will not display? 2. How can I use tal so that I don't have to hard code my portal URL path (like href="/my.portal.edu/news")? I want something like href="$portal_url/news"). 3. Any online ref/example of how to use the Tal/python scripts with ZOPE/CMF/Templates with small example will be helpful. Thanks, Gautam
Gautam Saha wrote at 2003-11-17 08:54 -0600:
... Here are my questions:
1. How to get the ID of an object (say "news" in this case so that I can conditionally suppress the HREF, so that if I am in the $portal_url/news page, the link will not display?
If "o" is a Zope object "o.getId()" (as a python expression; it is "o/getId" as path expression) is its id. When you call a template, then inside it "template" refers to the template, i.e. "template.getId()" is the template's id.
2. How can I use tal so that I don't have to hard code my portal URL path (like href="/my.portal.edu/news")? I want something like href="$portal_url/news").
If you call "portal_url", it returns the portal's URL. You can use this in a TALES "string" expression: "string: ${container/portal_url}/news"
3. Any online ref/example of how to use the Tal/python scripts with ZOPE/CMF/Templates with small example will be helpful.
Read the Zope Book (2.6 edition) and look into the "Examples" folder of "Products/PageTemplates". -- Dieter
Thanks a lot Dieter, for your response. I actually figure it out by looking at some codes and by using the template.getId() as suggested by you. Regards, Gautam -- Here is what I did if any one is interested: =============== Code in my news_slot.pt file ============== <!-- Link to news Archive from the News Slot --> <p metal:define-macro="news_link"> <span tal:condition="python:test(template.getId()!= 'news', 1,0)"> <a href="news" tal:attributes="href string:$portal_url/news"> <img tal:replace="structure here/linkTransparent.gif" /> <span tal:omit-tag="" i18n:translate="news_archive">News Archive</span> </a> </span> </p> ============= End of Code ============== Dieter Maurer wrote:
Gautam Saha wrote at 2003-11-17 08:54 -0600:
... Here are my questions:
1. How to get the ID of an object (say "news" in this case so that I can conditionally suppress the HREF, so that if I am in the $portal_url/news page, the link will not display?
If "o" is a Zope object "o.getId()" (as a python expression; it is "o/getId" as path expression) is its id.
When you call a template, then inside it "template" refers to the template, i.e. "template.getId()" is the template's id.
2. How can I use tal so that I don't have to hard code my portal URL path (like href="/my.portal.edu/news")? I want something like href="$portal_url/news").
If you call "portal_url", it returns the portal's URL.
You can use this in a TALES "string" expression:
"string: ${container/portal_url}/news"
3. Any online ref/example of how to use the Tal/python scripts with ZOPE/CMF/Templates with small example will be helpful.
Read the Zope Book (2.6 edition) and look into the "Examples" folder of "Products/PageTemplates".
participants (2)
-
Dieter Maurer -
Gautam Saha