Jump to content

Solved: How to use an $var in a hanna code


pwired
 Share

Recommended Posts

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 ?

 

Link to comment
Share on other sites

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');

 

  • Like 1
Link to comment
Share on other sites

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.

 

  • Like 1
Link to comment
Share on other sites

  • pwired changed the title to Solved: How to use an $var in a hanna code

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...