Render to Frontend with template Markdown or Code #8599
-
Hi there, I'm a newbie. Description: In backend i use fields Result in frontend and I want to show in frontend with template same bellow or same bellow. It maybe same Torchlight plugin Please help me. Thanks so much |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hey 👋🏻 I've written a blog post about setting up Torchlight and Bard in Statamic, if you're interested. If you'd prefer to use something local (eg. without the need for sending API requests for code embeds), you could look at implementing something like Shiki. Here's a very quick tag I've created for Shiki: <?php
namespace App\Tags;
use Illuminate\Support\Facades\Cache;
use Spatie\ShikiPhp\Shiki as ShikiPhp;
use Statamic\Tags\Tags;
class Shiki extends Tags
{
/**
* The {{ shiki :code="code" :language="language" }} tag.
*
* @return string|array
*/
public function index()
{
return Cache::rememberForever('ShikiHighlight::'.md5($this->params->get('code').$this->params->get('language')), function () {
return ShikiPhp::highlight(
code: $this->params->get('code'),
language: $this->params->get('language'),
theme: 'slack-ochin',
);
});
}
} {{ shiki :code="code" :language="language" }} |
Beta Was this translation helpful? Give feedback.
Hey 👋🏻
I've written a blog post about setting up Torchlight and Bard in Statamic, if you're interested.
If you'd prefer to use something local (eg. without the need for sending API requests for code embeds), you could look at implementing something like Shiki.
Here's a very quick tag I've created for Shiki: