views:

47

answers:

1

I would like to have per-page sidebar content in Zotonic:

  • Links
  • White papers
  • Webinars

What is a good way to do this and what kind of template snippets would I need to make it work?

A: 

Log into the Zotonic admin interface.

Create Predicates:

  • Links (text->text)
  • White papers (text->document)
  • Webinars (text->text)

These predicates then show up in Page Connections in the Page editor. Add Links to other pages, links to White papers and links to Webinar pages in this way.

Add the following to _article_sidebar.tpl:

{% with m.rsc[id].links as texts %} 
  {% if texts %}
    <h2>See also:</h2>
    <ul>
    {% for text in texts %}
      <li><a href="{{ m.rsc[text].page_url }}" {% ifequal text id %}class="current"{% endifequal %}>{{ m.rsc[text].title }}</a></li>
    {% endfor %}
    </ul>
  {% endif %}
{% endwith %}

{% with m.rsc[id].white_papers as texts %} 
  {% if texts %}
    <h2>White papers:</h2>
    <ul>
      {% for text in texts %}
        <li><a href="{{ m.rsc[text].page_url }}" {% ifequal text id %}class="current"{% endifequal %}>{{ m.rsc[text].title }}</a></li>
      {% endfor %}
    </ul>
  {% endif %}
{% endwith %}

{% with m.rsc[id].webinars as texts %} 
  {% if texts %}
    <h2>Related webinars:</h2>
    <ul>
      {% for text in texts %}
        <li><a href="{{ m.rsc[text].page_url }}" {% ifequal text id %}class="current"{% endifequal %}>{{ m.rsc[text].title }}</a></li>
      {% endfor %}
    </ul>
  {% endif %}
{% endwith %}

When you add a Predicate it lets you add metadata to your RSCs (Pages, Media, etc.) in Zotonic. Each Predicate allows you to connect a collection of RSCs to a RSC in the Zotonic interface. This collection is stored and accessed as IDs of RSCs.

Predicate metadata are then accessible within templates. The expression m.rsc[id].links selects the collection of IDs of RSCs connected to the current page as Links.

The expression m.rsc[id] selects the RSC for the page being rendered. The expression m.rsc[text] selects the RSC for a onnected RSC.

The expression {% ifequal text id %}class="current"{% endifequal %} conditionally renders a CSS class attribute that alters the link style to indicate that it is the current page.

Alain O'Dea