pwired Posted August 9, 2022 Posted August 9, 2022 Hi, I am using a hanna code in a ckeditor field [[timeline]] In the _init.php I have declared $home_sidebar_timeline = $includes_path . "home_sidebar_timeline.php"; Can I use variables declared in the _init.php in a hanna code ? I have this php code in my hanna code: <?php include $home_sidebar_timeline; ?> When I put the hanna code [[timeline]] in a ckeditor field it doesn't work. How can I use a variable declared in the _init.php in a hanna code Do I need to use global variables ?
Jan Romero Posted August 9, 2022 Posted August 9, 2022 I imagine global variables might work, but I would probably but it into $config->paths: https://processwire.com/api/ref/paths/ 1
pwired Posted August 9, 2022 Author Posted August 9, 2022 Hello Jan Thanks for replying on this. Instead of declaring my own file and url paths, using Processwire's api $config->paths hopefully will make it work I will try it and post back about it
Jan Romero Posted August 9, 2022 Posted August 9, 2022 Sorry, I was a bit terse. To be clear, I meant storing your custom path in the $config->paths object, somewhat like this: // config.php (or init.php) $config->paths->set('home_sidebar_timeline', $includes_path . 'home_sidebar_timeline.php'); Then you should be able to get it from anywhere anywhere like this: include $config->paths->home_sidebar_timeline; //or include $config->paths->get('home_sidebar_timeline'); 1
pwired Posted August 9, 2022 Author Posted August 9, 2022 Quote // config.php (or init.php) $config->paths->set('home_sidebar_timeline', $includes_path . 'home_sidebar_timeline.php'); Ah yes I forgot about make use of the config.php (or init.php) ..... thanks for pointing me there, will try that too. The paths that I declared in the _init.php ..... I simply declared them again on top of my hanna php code and now my hanna code is working in my ckeditor field So either way what will work I mark the question as solved. Note - did you guys know you can render a hanna code directly in a template like this: $hanna = $modules->get('TextformatterHannaCode'); echo $hanna->render("[[my_hanna_snippet]]"); https://processwire.com/talk/topic/14141-outputting-a-hanna-code-via-the-api-in-a-template/ Hanna Code is actually a powerful option. 1
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now