New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Include other files #441
Comments
Sculpin uses the Twig template engine, which has an For content that you don't want rendered out to HTML directly, you might want to put it in the |
@beryllium thanks, but it doesnt seem to work:
|
This was more challenging than I expected at first. Putting the example Here is the approach I took to enable your example to work:
So it seems as though Setting custom values in
At which point you could store the |
@beryllium thanks very much, but I dont think that is going to work for my use
I am using something like this now with Hugo, but I am looking to move away from |
Looks like this isn't a use case that Sculpin would be able to support without an alternative approach (e.g., delving into the code to create a twig extension that acts like readFile - quite a hassle compared to an out-of-the-box solution, if one can be found). Another issue is that the Such an extension would look something like this: <?php
class TwigReadFileExtension extends Twig_Extension
{
protected $sourceDir;
public function __construct($sourceDir)
{
$this->sourceDir = $sourceDir;
}
public function getName()
{
return 'readfile_extension';
}
public function getFunctions()
{
$sourceDir = $this->sourceDir;
return array(
new \Twig_SimpleFunction('readfile', function ($file) use ($sourceDir) {
// @todo add extra logic to prevent filesystem escape & to clean up concatenated path
return file_get_contents($sourceDir . $file);
}
);
}
} And it would be configured in the services:
readFileExtension:
class: TwigReadFileExtension
arguments:
$sourceDir: '%sculpin.sourceDir%'
tags:
- 'twig.extension'
public: true The suggestions above are untested, so there might be unexpected roadblocks. For example, autoloading won't know where to look out of the box without configuring composer.json for it, so adding a manual |
Darn, I thought I had something. I see reStructuredText has ability to include https://docutils.sourceforge.io/docs/ref/rst/directives.html#include bypassing any need to Sculpin to do it. However RST is not supported with |
Currently it seems it is not possible to include a file, is that the case? Other
projects have this built in:
https://gohugo.io/functions/readfile
The text was updated successfully, but these errors were encountered: