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
Add attributes variable to templates #2292
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am in favor of this - however I would like this to be expanded to other templates as well, e.g.
block_searchable
block_unsearchable
and any template that does not inherit from the block templates, e.g. ce_headline
for example.
<<?= $this->hl ?> class="<?= $this->class ?>"<?= $this->cssID ?><?php if ($this->style): ?> style="<?= $this->style ?>"<?php endif; ?><?= $this->attributes ?>>
<?= $this->headline ?>
</<?= $this->hl ?>>
Although technically you could (mis)use $this->cssID
for that purpose in those templates.
@@ -21,7 +21,7 @@ | |||
<?php $this->endblock(); ?> | |||
|
|||
</head> | |||
<body id="top"<?php if ($this->class): ?> class="<?= $this->class ?>"<?php endif; ?><?php if ($this->onload): ?> onload="<?= $this->onload ?>"<?php endif; ?> itemscope itemtype="http://schema.org/WebPage"> | |||
<body id="top"<?php if ($this->class): ?> class="<?= $this->class ?>"<?php endif; ?><?php if ($this->onload): ?> onload="<?= $this->onload ?>"<?php endif; ?> itemscope itemtype="http://schema.org/WebPage"<?php if ($this->attributes): ?> <?= $this->attributes ?><?php endif; ?>> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<body id="top"<?php if ($this->class): ?> class="<?= $this->class ?>"<?php endif; ?><?php if ($this->onload): ?> onload="<?= $this->onload ?>"<?php endif; ?> itemscope itemtype="http://schema.org/WebPage"<?php if ($this->attributes): ?> <?= $this->attributes ?><?php endif; ?>> | |
<body id="top"<?php if ($this->class): ?> class="<?= $this->class ?>"<?php endif; ?><?php if ($this->onload): ?> onload="<?= $this->onload ?>"<?php endif; ?> itemscope itemtype="http://schema.org/WebPage"<?= $this->attributes ?>> |
I think it should be without a space, as the same concept is used in a few other templates already.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed it in my latest commit.
Not necessarily. I'd just use it in an |
@fritzmg Should I adjust the other template in this pull request or an follow up? |
Just do it in this one :) |
@contao/developers wdyt? |
I think the name Speaking of the last: I think we shouldn't introduce more precompiled things to the templates. Associative data should imo be in an array. If it gets to cumbersome to output there can still be a template function. Similar story in the Idk, brainstorming: $pageRegular->Template->attributes['data-custom'] = 'customThing'; <?php echo $this->expand($this->attributes); ?> // data-custom="customThing" foo="f" bar="b"
<?php echo $this->expand($this->attributes, 'foo', 'bar'); ?> // foo="f" bar="b" |
While I agree, the fact is that it is already used this way in Contao. This PR would just expand that concept to all other templates.
👍 :) |
This litte PR adds an attributes variable to the body tag to add custom (data) attributes to the body tag without the need to complete override the fe_page template. As this is a very small addition, I would love to see this also merged in the contao 4.9 and 4.4 branch.
Usage example:
Update:
After discussion this pull request also adds the attributes variable to block templates and all module and element template not inheriting from block templates.