Hi to everyone,
I am wondering if it is possible to have a page title with two different styles.
Something like this for instance “something”.
I have to do a menu with only one voice in this way and I can’t figure how to do that.
Thanks
R.
Hi to everyone,
I am wondering if it is possible to have a page title with two different styles.
Something like this for instance “something”.
I have to do a menu with only one voice in this way and I can’t figure how to do that.
Thanks
R.
Not quite sure I get what you are trying to achieve. When are the styles supposed to change?
In the page title inside a word like something ore something etc etc
I would like to have half word with a style and the other half with an other style.
Maybe due to the fact that is not possible to format the page title I have to set a text field that will be displayed in the menu. So the title of the page will be “something” and the menu item will be “something”. Am I wrong?
Thank you for your quick answer
Rosario
Depends on your criteria for splitting the string:
E.g. by position:
<?php
$title = $page->title()->value();
$pos = 5;
list($start, $end) = preg_split('/(?<=.{'.$pos.'})/', $title, 2);
?>
<h1><span class="start"><?= $start ?></span><span class="end"><?= $end ?></span></h1>
That’s only one way of doing that. Really depends on your criteria where you want to split the title.
Kirby’s Str
class has some methods that might be useful for you: https://getkirby.com/docs/reference/tools/str
Thank you for your answer and sorry for the late reply…
Unfortunately there is no criteria and it happens only in one case.
I can survive without the two different styles
You could do if manually. For example in your loop, check if the title is the one you want to style:
<?php foreach ($pages as $page) {
if ($page->title()->value() === 'Something'): ?>
<h1><span class="start">Some</span><span class="end">thing</span></h1>
<?php else: ?>
<h1><?= $page->title()->html() ?></h1>
<?php endif ?>
<?php endforeach ?>
This is a good solution, I’ll try.
Thank you
Maybe I make a mistake in the code…
<?php foreach($items as $item): {
if ($page->title()->value() === 'Something'): ?>
<li><a<?php e($item->isOpen(), ' class="active"') ?> href="<?= $item->url() ?>"><span class="start">Some</span><span class="end">thing</span></a></li>
<?php else: ?>
<li><a<?php e($item->isOpen(), ' class="active"') ?> href="<?= $item->url() ?>"><?= $item->title()->html() ?></a></li>
<?php endforeach ?>
Missing endif
<?php foreach($items as $item): ?>
<?php if ($page->title()->value() === 'Something'): ?>
<li><a<?php e($item->isOpen(), ' class="active"') ?> href="<?= $item->url() ?>"><span class="start">Some</span><span class="end">thing</span></a></li>
<?php else: ?>
<li><a<?php e($item->isOpen(), ' class="active"') ?> href="<?= $item->url() ?>"><?= $item->title()->html() ?></a></li>
<?php endif ?>
<?php endforeach ?>
Thank you, I made an other mistake so this is the final version
<?php foreach($items as $item): ?>
<?php if ($item->title()->value() === 'Something'): ?>
<li><a<?php e($item->isOpen(), ' class="active"') ?> href="<?= $item->url() ?>"><span class="start">Some</span><span class="end">thing</span></a></li>
<?php else: ?>
<li><a<?php e($item->isOpen(), ' class="active"') ?> href="<?= $item->url() ?>"><?= $item->title()->html() ?></a></li>
<?php endif ?>
<?php endforeach ?>