zoomyboy
zoomyboy

Hello people,

In the original rtwig language, I can define something like a slot to change some code when importing a partial.

Also, this seems to be poossible in E-Mails, since the default email markup uses it.

Do you know if this is possible in October version 2?

Cheers Philipp

daftspunky
daftspunky

Hi there,

I'm not entirely sure, are you talking about {% placeholder %} tags as described here? https://octobercms.com/docs/markup/tag-placeholder

zoomyboy
zoomyboy

I'm basically trying to do it the same way as Vue, Twig, etc does. So imagine you have a card partial to display a card on the page - with 3 parameters: body, header and image. You could maybe define the image and the body as parameters directly:

{% partial card title="Hello there" image="img.jpg" %}{% endpartial %}

This is fine, but not "good enough" yet, because the body of the card is an attribute which is not suitable for long text or even html content (because you would need to escape all the double quotes in html attributes which is really hacky).

It would be better to define the body directly inside of the partial:

{% partial card title="Hello there" image="img.jpg" %} partial body {% endpartial %}

It seems that October can already do this, because it is actually used inside of mail layout to render a subcopy. Howeber, this code is not valid inside of a CMS page (meaning the partial body is stripped):

{% partial 'subcopy' body %}
  **This is an automatic message. Please do not reply to it.**
{% endpartial %}

Also, what if I wanna have html inside of the card header? That would be a good usecase of a "partial slot" which is rendered as the card header and can be overwritten if desired. Inside twig, this feature seems to be possible with blocks. https://twig.symfony.com/doc/2.x/tags/extends.html

But blocks are - for whatever reason - not available in October as far as I know. In my mind, this is one of the most powerful features of twig - so why is it removed to make twig "october compatible"?

In the end, this could look something like this:

{% partial 'card' image="img.jpg" %}
  {% slot header %}
    <h2>This is the card header</h2>
  {% endslot %}
  **This is an automatic message. Please do not reply to it.**
{% endpartial %}

Not being able to define slots inside partials makes this whole concept of developing october cms themes a lot less useful for me, because I still have to spread code duplications all over the place. Maybe, I'm doing something wrong here and you have a better way, but this really sucks...

Thanks for your suggestions.

daftspunky
daftspunky

Ok, this makes sense, thank you for the explanation. We will add the partial+body functionality to be available in v2.0.25. Here's how it could be used to satisfy your requirements.

Page contents (pages/home.htm)

{% partial 'card' image="img.jpg" body %}
    {% put header %}
        <h2>This is the card header</h2>
    {% endput %}
    This is the card contents
{% endpartial %}

Partial contents (partials/card.htm)

<div class="header">
    <div class="image">
        <img src="{{ image }}" />
    </div>
    {% placeholder header %}
</div>
<div class="body">
    {{ body|raw }}
</div>
zoomyboy
zoomyboy

Thanks for the explanation. Didn't know that this is already working - even in plain CMS pages. But can you use the placeholder "header" across multiple partial imports on the same page (meaning the placeholder behaves like a local variable inside of the current partial scope)? Or would they overwrite each other since all the placeholders have the same name in the page's scope?

daftspunky
daftspunky

zoomyboy said:

But can you use the placeholder "header" across multiple partial imports on the same page (meaning the placeholder behaves like a local variable inside of the current partial scope)?

Yes. In our testing, it appears to work fine so long as the scope is constrained to the body portion of the partial. They don't overwrite each other, even though they share the same placeholder name, due to the execution lifecycle.

vimre
vimre

@daftspunk: Is this feature documented somewhere?
I found it on changelog page then tried to search for details on docs section but I found nothing there, then I found this post on the forum.
I think it would be nice to have some links in changelog in such cases that could point to the related parts of the documentation or to the forum (if the idea of the feature came from some conversation on the forum). What do you think?

daftspunky
daftspunky

vimre said:

@daftspunk: Is this feature documented somewhere?

Yes, you can find it in the documentation here: https://octobercms.com/docs/cms/partials#partial-markup-variable

1-8 of 8