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 template listing projects in a folder #282

Open
arranger1044 opened this issue Jun 8, 2015 · 2 comments
Open

Dynamic template listing projects in a folder #282

arranger1044 opened this issue Jun 8, 2015 · 2 comments

Comments

@arranger1044
Copy link

I am trying to create a jinja2 template that lists all the pages in a folder (little html files representing projects in my /projects dir) showing their meta attributes like title, description and putting some links as details, if present, taken from a list of meta attributes (github in the example).

Given the scarce documentation out there, this is what I've come up with:

{% for res in resource.node['resources']|sort(attribute='meta.created') %}
{% if res.meta.title != 'projects' %}
  <h2><a href="{{res.url}}">{{res.meta.title}}</a></h2>
<p> {{res.meta.description}}
  {% set show_details = [] %}
  {{res.meta.__dict__}}
  {% for d in details %}
    {% if d in res.meta.__dict__  %}
       {% do show_details.append(d) %}
    {% endif %}
  {% endfor %}

  {% if show_details %}
     [{% for d in show_details %}
         <a href="{{res.meta.__dict__[d]}}">{{d}}</a>
     {% if loop.index < show_details|length %}
     | 
    {% endif %}
     {% endfor %}]
  {% endif %}
  </p>
  <!--<hr/>-->
  {% endif %}
{% endfor %}   

This seems to get the job done, however I am not totally satisfied with it, so I am asking:

  • is there a better, 'native' way in Hyde to achieve this?
  • the side effect of this approach is that the above template is not compiled again when I simply modify my files in project folder and then call hyde gen, is this solvable?
@moggers87
Copy link
Contributor

Try hyde gen -r as a work around for your last point.

@arranger1044
Copy link
Author

@moggers87 thanks for pointing it out!
According to your experience, am I doing something 'right' (at least within Hyde's philosophy)?

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