django-cms / djangocms-style

django CMS Style is a plugin for django CMS that allows you to create a HTML container containing classes, styles, ids and other attributes.
https://marketplace.django-cms.org/en/addons/browse/djangocms-style/
Other
38 stars 22 forks source link

Add templates for styles? #27

Closed bhrutledge closed 7 years ago

bhrutledge commented 7 years ago

I'm not sure this is the right place for this suggestion, or if it's already been done elsewhere, but here goes...

I think it would be handy to associate a Django template with entries in DJANGOCMS_STYLE_CHOICES, similar to how djangocms-link and -picture have optional templates.

My immediate use case is a "Recommended for You" section, with markup that looks something like this:

<section class="rec-section">
    <h2>Recommended For You</h2>
    <div class="rec-list">
        <a class="rec-item" href="...">
            <img class="rec-thumb" src="...">
            <div class="rec-title">First title</div>
        </a>
        <a class="rec-item" href="...">
            <img class="rec-thumb" src="...">
            <div class="rec-title">Second title</div>
        </a>
    </div>
</section>

Currently, to implement that, I think I my plugin structure would look something like this:

Style: .rec-section
  Text: <h2>Recommended For You</h2>
  Style: .rec-list
    Link: [href="..."]
      Text: .rec-thumb and .rec-title
    Link: [href="..."]
      Text: .rec-thumb and .rec-title

But, with a template that's mapped to .rec-section, and contains the h2 and div.rec-list wrapper, the structure could be:

Style: .rec-section
  Link: [href="..."]
    Text: .rec-thumb and .rec-title
  Link: [href="..."]
    Text: .rec-thumb and .rec-title
FinalAngel commented 7 years ago

@bhrutledge we are most likely going to introduce a separate DJANGOCMS_STYLE_TEMPLATES setting to support multiple templates. Though I do not understand your use case. You would still have to add the

text in the content or would you add it hardcoded to the template?

bhrutledge commented 7 years ago

Happy to see that this is already done! I'm imagining my template will be something like this (with the addition of other instance attributes):

<section class="rec-section">
    <h2>Recommended For You</h2>
    <div class="rec-list">
        {% for plugin in instance.child_plugin_instances %}{% render_plugin plugin %}{% endfor %}
    </div>
</section>

IE, the link/image/text content will come from child plugins of the style.

FinalAngel commented 7 years ago

@bhrutledge perfect, just so I understand the use case, that's what I'd have done. It will be integrated in the next release (around tomorrow). Just be aware that DJANGOCMS_STYLE_CHOICES and DJANGOCMS_STYLE_TEMPLATES are two separate settings.