Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamic node names #11

Open
satyrius opened this issue Oct 8, 2014 · 1 comment
Open

Dynamic node names #11

satyrius opened this issue Oct 8, 2014 · 1 comment

Comments

@satyrius
Copy link

satyrius commented Oct 8, 2014

How to create a few nodes in a template with auto-generated names (e.g. for column design)

{% blocknode 'page/column-1.md' %}
  ## Luke
{% endblocknode %}
{% blocknode 'page/column-2.md' %}
  ## Leia
{% endblocknode %}
{% blocknode 'page/column-3.md' %}
  ## Han
{% endblocknode %}

I want do it like this

{% with forloop.counter|format:"page/column-%s.md" as uri %}
  {% blocknode uri %}
    ## Luke
  {% endblocknode %}
{% endwith %}

But got and error

Unknown plugin "None" or improperly configured pipeline for node "i18n://ru-ru@".
@lundberg
Copy link
Contributor

lundberg commented Oct 8, 2014

Due to underlaying cache performance, dynamic nodes URI's can not be used.

All URI's gets picked up by content-io when the template is parsed, and then hydrated against cache (i.e. memcached) in bulk when the first node gets rendered. This is to reduce latency and increase page speed.

What you can do is to prepare your wanted nodes in the view instead, and add them to the context.
By doing this, the same performance is kept because the node objects from content-io is lazy.
Unfortunately you wont be able to "click" on the nodes to edit since the template tag is not used, and you need to choose the nodes from the djedi admin panel.

Example (dummy code, not tested ;-)

# views.py
import cio
def foobar(request):
    column_nodes = [cio.get('page/column-{}.md'.format(i)) for i in range(1, 4)]
    return render(.....{'column_nodes': column_nodes})
<!-- template -->
<body>
    {% for node in column_nodes %}
        {{ node }}
    {% endfor %}
</body>

We have a fragment of another extra template tag (not released yet) that could handle a node object instead of the URI to get the inline click/edit feature together with node objects from context.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants