Closed BananaAcid closed 4 years ago
Hello,
Complete API reference for parameters and return types is here: https://phug-lang.com/api/classes/Phug.Renderer.Partial.CacheTrait.html#method_cacheFileIfChanged
As you can see it takes just a string:
$renderer->cacheFileIfChanged('views/page.pug'); // will be cached if change since the last time it was cached
// Can also be called with the facade:
// Phug::cacheFileIfChanged('views/page.pug');
I tried a lot, and tried to understand the API docs, but I believe some more exemplary documentation on the front page could help people to get going easier.
Some example like this maybe: (I am not entirely sure, the cached file is actually used, or what is actually cached - I believe the compiled pug without the data. )
include_once __DIR__ . '/../vendor/autoload.php';
Phug::setOptions(['cache_dir' => sys_get_temp_dir() ]);
Phug::cacheFileIfChanged('../src/pug/index.pug');
Phug::displayFile('../src/pug/index.pug', ["data" => json_decode(file_get_contents(...)) ]);
You don't need to call cacheFileIfChanged
if you're using the option 'cache_dir'
then displayFile
will cache the result automatically, as described in the option documentation:
https://phug-lang.com/#cache-dir-boolean-string
An example with 'cache_dir'
is also provided in the displayFile
section:
https://phug-lang.com/#displayfile
Thanks for the clarification.
The info is too scattered, It is quite confusing. "This option is automatically handled when you use framework " made me think, I would need to use any of these cacheFile* functions.
It would be great, having these anchor links in the documentation, e.g. options being linked to the options example it is referring to.
Hello,
I encountered an issue with the following documentation: https://phug-lang.com/#cachefileifchanged
I am not sure, what the params are, the documentation is pretty scarce on this bunch of functions.
Clarification would be great.
Thanks!