This is my second using kirby, I’m very much a noob in php and how kirby functions so forgive me. I need to convert a string into a safe string with no spaces. This my current code:
$string = '<?= $project->title()->html() ?>';
What is the correct way of writing this?
If you wrap the PHP code in single quotes, it won’t get executed:
$string = $project->title();
(Please note that
$string is not really a string this case;
$page->title() returns an object of type field, which is converted to a string by the
__toString() magic method.)
If you needed
$string to be a real string, you could use the
value() field method:
$string = $project->title()->value();
You don’t need the variable, though:
data-slug="<?php echo str::slug($page->title())?>"
Thank you for explaining that to me. Kirby is fantastic