Calling a non-existing snippet

Hello,

I assume if I call a snippet that does not exist, nothing echoes and that is it, correct ? (could not find the code for App::instance()->snippet())

Thanks

That’s right, if a snippet doesn’t exist, nothing is rendered. You could use fallback snippets.

Thank you, I assume that if I wanted to return something ‘default’ by default , meaning, without specifying it in every snippet, I’d need to substitute snippet() (in case it can be substituted).

Do you know where is App::instance()->snippet() ?

Thank you

You could check if what is returned from your snippet function call is an empty string and then output some text.

$snippet = snippet('my-snippet', [], true);
if ('' === $snippet) {
  echo 'The snippet does not exist or does not return anything';
} else {
  echo $snippet;
}
1 Like