Open ghost opened 6 years ago
@texnixe commented on Jul 28, 2018, 10:00 PM UTC:
I actually don't really think HTML template code should be written like this. It might be readable for developers, but probably isn't for designers and the HTML and the logic should be clearly separated.
@wottpal commented on Jul 30, 2018, 12:16 PM UTC:
I think it's a question of taste and we should not write code with people in mind who will never read it. I think for people who spend all day writing template code this solution will be just fine and very readable.
I created a plugin for it but not with the proposed syntax but $page->field()->tag('h2')
which looks really nice imho.
@wottpal commented on Jul 28, 2018, 11:23 AM UTC:
First: I know this could easily be a nice plugin but I truly believe every php-/kirby-beginner could profit of this DRY-way of writing template-code.
There is the
tag($name, $content, $attrs)
function we can use to easily generate various tags with different attributes and content. Like the documentation says when$content == ''
the tag is returned with not content - but it's returned. This is only useful in a very limited number of cases but often when it comes to templating you want no surrounding tag at all:Implementing this behavior as a default in the
tag()
function would make so much code shorter and more readable (thetag()
-function finally beneficial):(This example also assumes there is a
tag()
shorthand forKirby\Toolkit\Html::tag
)To still make the old behavior accessible there could be for example an
$allowEmpty
parameter at the end which defaults tofalse
.What do you think?
This issue was moved by bastianallgeier from k-next/kirby#771.