0
votes

I am working on generating a menu which allows the user to upload an image, and text description, to each subsection of the menu. Here is the current code (custom template for displaying a menu):

{% for lowest in lower.children %}
    {% with lowest.get_menu_title as title %}
        <div id="product_box">
            <div id="product_image">
                {% placeholder title %}
            </div>
        </div>
        <div id="product_summary">
            <h3>
                <a href="{{ lowest.attr.redirect_url|default:lowest.get_absolute_url }}">
                                    {{title}}
                </a>
            </h3>
            <p>
                {% placeholder "Text" %}
                <a href="{{ lowest.attr.redirect_url|default:lowest.get_absolute_url }}">Learn More</a>
            </p>
        </div>
    {% endwith %}
{% endfor %}

(Don't worry about the {% placeholder "Text" %} right now, I simply haven't changed that part yet since I can't get the former working). The page renders, but only the only plugins visible are "TITLE" and "Text" (again, no worries about "text").

I haven't found any documentation stating that placeholders can't be named using variables, but so far everything I've tried , from {{title}} to {% placeholder lowest.get_menu_title %} all just seem to interpret those as strings, displaying {{TITLE}} or LOWEST.GET_MENU_TITLE as the placeholder name, respectively.

So, my question is: Can I assign a variable name in the template to a placeholder (so that I can generate unique placeholders in a for loop, based on menu names)?

3

3 Answers

0
votes

From looking through the codebase here: https://github.com/divio/django-cms/blob/develop/cms/templatetags/cms_tags.py#L284 it appears that the 'name' argument to the placeholder template tag is always interpreted as a string, so, it cannot currently be a variable assignment.

Its not completely clear what you intend to do here, but I wonder if you should instead look into using a django model to represent all your various instances, then use a PlaceholderField (http://django-cms.readthedocs.org/en/support-3.0.x/how_to/placeholders.html). You still won't be able to define/reference the placeholders through template variables, but you could then iterate through your instances and display their PlaceholderField in turn.

Hope this helps.

0
votes

If it's possible to use static placeholders, you could use the add built-in template filter to construct the string, then pass it to the placeholder tag.
For instance:

{% static_placeholder title|add:"-placeholder" %}
0
votes

There is a workaround:

{% with child.title as name %}{% static_placeholder name %}{% endwith %}

I've used this to add customizable links into an navigation bar menu. the result was suprising stable.

Now I've creatated an private page for our designers to customize the menus.

on the page gets an list generated from the {% show_menu %} , one with the actual navigation bar template and an list with the predefined placeholders.

sadly these placeholders have to be predefined as no placeholder from an template gets rendered in the structure board