Jump to content

Hanna Code


ryan

Recommended Posts

On 10/27/2017 at 11:35 PM, abdus said:

Assuming _func.php is under templates folder, you need to include _func.php in your hanna code like this:


<?php 

include_once $config->paths->templates . '_func.php';

echo "<div class=\"grid_xs-1\">";
foreach ($pages->find("template=property") as $properties) {
// ...

 

@abdus That's exactly what i supposed, tried, and what did not work. Try to call from that template code a function defined in _func.php...

Link to comment
Share on other sites

  • 1 month later...
  • 2 weeks later...
5 hours ago, mr-fan said:

Has anyone a script to get all specific pages that uses a special hanna code...

give me me all pages with [[my-hanna-code]] in use?

You can search for the text string that makes up the start of the tag (to allow for varying attributes).

// Get fields with TextformatterHannaCode applied
$hanna_fields = array();
foreach($fields as $field) if(is_array($field->textformatters) && in_array('TextformatterHannaCode', $field->textformatters)) $hanna_fields[] = $field->name;
// Implode for use in selector string
$hanna_fields = implode('|', $hanna_fields);
// Find pages with a given Hanna tag
$has_hanna = $pages->find("$hanna_fields*=[[your_tag");

 

  • Like 2
Link to comment
Share on other sites

Thank you Robin - will try asap!
[ot]At the moment i'm a little but lethal snuffy...and could not think clearly (i think it is deadly man-flu). So don't think i'm to lazy to search a solution...i'm not...i've read your code and it was clear for me that my question was silly...i'm just standing a little beside me but i think that the peak of my desease is done. :lol:[/ot]

Best regards mr-fan

  • Like 1
Link to comment
Share on other sites

  • 1 month later...

I'm using Hanna code to embed content from different pages on a site. What I would need is a way to get the created and modified date of the page that has been embedded. I need to use/show these dates in the front-end of the page that has the embedded content. Is there some elegant way I could get this information?

Link to comment
Share on other sites

16 minutes ago, nikoka said:

I'm using Hanna code to embed content from different pages on a site. What I would need is a way to get the created and modified date of the page that has been embedded. I need to use/show these dates in the front-end of the page that has the embedded content. Is there some elegant way I could get this information?

I always get confused about this. Try accessing it using wire('page') and see if that helps.

Quote

The $page API variable available to your Hanna code represents the page where the Hanna code exists.It is possible for this to be different from wire('page'), which represents the page that originated the request.

From the PHP Usage notes section on here

http://modules.processwire.com/modules/process-hanna-code/

Edited by kongondo
Link to comment
Share on other sites

Thanks @kongondo, I was a bit unclear, I have a page (let's call it page A) with and embedded page (let's call it page B). I need to show the modified/created dates of page B on page A. But how do I get this information from the embedded page B to the "wrapper" page A?   

Link to comment
Share on other sites

7 hours ago, nikoka said:

Thanks @kongondo, I was a bit unclear, I have a page (let's call it page A) with and embedded page (let's call it page B). I need to show the modified/created dates of page B on page A. But how do I get this information from the embedded page B to the "wrapper" page A?   

What does your hanna code look like? 

Link to comment
Share on other sites

10 hours ago, kongondo said:

What does your hanna code look like? 

The tag I use for adding embedded page content is: [[single-source url=""]] For the url I add the page ID and the content is then shown. There's a bunch of other things happening, but the essence of the hanna code for getting the embedded page content goes like this: 

$return = $attr["url"];
$id = (int) $return;
$embeddedPage = $pages->get($id);
echo $embeddedPage->body;

 

Link to comment
Share on other sites

2 hours ago, nikoka said:

The tag I use for adding embedded page content is: [[single-source url=""]] For the url I add the page ID and the content is then shown. There's a bunch of other things happening, but the essence of the hanna code for getting the embedded page content goes like this: 


$return = $attr["url"];
$id = (int) $return;
$embeddedPage = $pages->get($id);
echo $embeddedPage->body;

 

I must be missing something then. Do you:

  1. Want to grab $embeddedPage and use it later on in your page or
  2. Want to echo $embeddedPage properies (body, created, etc) right within your Hanna Code?

If #2, you are already doing it by echo $embeddedPage->body. E.g., the following works correctly for me (code in the Hanna Code itself)

$return = $attr["url"];
$id = (int) $return;
$embeddedPage = $pages->get($id);
echo $embeddedPage->body;
$modified = $embeddedPage->modified;
echo date("l jS \of F Y h:i:s A", $modified);

I have this Hanna Code Tag in Page A, where 1049 is the ID of Page B.

[[test url=1049]]

That outputs Page B's modified date.

But this seems too easy. I have a feeling I'm still not getting you.

Edited by kongondo
  • Like 2
Link to comment
Share on other sites

5 minutes ago, kongondo said:

I must be missing something then. Do you:

  1. Want to grab $embeddedPage and use it later on in your page or
  2. Want to echo $embeddedPage properies (body, created, etc) right within your Hanna Code?

If #2, you are already doing it by echo $embeddedPage->body. E.g., the following works correctly for me (code in the Hanna Code itself)


$return = $attr["url"];
$id = (int) $return;
$embeddedPage = $pages->get($id);
echo $embeddedPage->body;
$modified = $embeddedPage->modified;
echo date("l jS \of F Y h:i:s A", $modified);

I have this Hanna Code Tag in Page A, where 1049 is the ID of Page B.


[[test url=1049]]

That outputs Page B's modified date.

But this seems too easy. I have a feeling I'm still not getting you.

Thanks for sticking with me @kongondo :) Number 1 is what I want to do. I need to use the modified/created dates of Page B to compare to the modified/created dates of Page A and insert some badges on Page A according to which of these pages have been updated more recently. 

Link to comment
Share on other sites

1 hour ago, nikoka said:

I need to use the modified/created dates of Page B to compare to the modified/created dates of Page A and insert some badges on Page A according to which of these pages have been updated more recently. 

I've quickly had a look at the Hanna Code page and couldn't find any API to achieve what you are after. The only things I can think of are cookies or session. You can save the ID of Page B in a session or the values of Page B that you are after (modified, created, etc)

$return = $attr["url"];
$id = (int) $return;
$embeddedPage = $pages->get($id);
echo $embeddedPage->body;
$modified = $embeddedPage->modified;
//echo date("l jS \of F Y h:i:s A", $modified);
$session->set('my_page_id', $id);
// $session->set('my_page_modified', $modified);

You can then grab the value using 

$modifiedDate = $session->get('my_page_modified');

 

  • Like 3
Link to comment
Share on other sites

That's a great idea, thank you so much @kongondo!

This seems to work and I can also see which page is embedded in which wrapper page: 

$return = $attr["url"];
$id = (int) $return;
$embeddedPage = $pages->get($id);
echo $embeddedPage->body;
$wrapperPage = $page->id;
$session->set($wrapperPage, $embeddedPage);

Then I grab the value like this:

$sourceID = $session->get($page->id);
echo date('Y-m-d', $pages->get($sourceID)->modified);

 

Link to comment
Share on other sites

  • 2 weeks later...

After having freshly installed HannaCode and Hanna Code Textformatter I encounter the following issue:

When, in the Module Settings for Hanna Code, I click on "check for updates", I get the following error message  (at the top, in red):

Quote

Session: Error reported by web service: Unable to find that module

What's going wrong?

(BTW: already on PW 3.096, but I think that doesn't matter.)

Link to comment
Share on other sites

On 18/03/2018 at 6:03 AM, ottogal said:

What's going wrong?

You have to check from the module which has its class name stored in the modules directory. For Hanna Code this is TextformatterHannaCode (not ProcessHannaCode).

For modules such as Hanna Code that contain additional sub-modules the simplest way to update is probably via ProcessWireUpgrade - then you don't need to think about which class name is the one stored in the modules directory.

  • Like 2
Link to comment
Share on other sites

In the Add Module From Directory dialogue I inserted the class name  TextformatterHannaCode and hit the button Download and Install.

The installation worked well.

When I look for updates of the TextformatterHannaCode module, there is the message Session: Current installed version is already up-to-date.

But not so trying to update the ProcessHannaCode module: I get the mentioned error message.

Link to comment
Share on other sites

  • 5 months later...

Convert Wordpress shortcodes with "end tags" to Hanna Code

I imported posts from a Wordpress site via WordpressMigrate Module. I used the Convert Shortcodes to Hanna Code Option. The Plan was to write some Hanna snippets to replace the former shortcode functionality. In most cases this works like a charm. But sometimes the codes uses kind of a Start - End Tag Syntax like this:

[[av_textblock size='' font_color='' color='']]
Some Text
[[/av_textblock]]


Anyone got an idea how to get a grip on this ? Is it possible with Hanna Code ?

Link to comment
Share on other sites

1 minute ago, adrian said:

[[av_textblock size='' font_color='' color='' text='Some Text']]

Although I think giving site editors the ability to change font size or color beyond selecting from <hx> tags is a bad idea for keeping a nice looking site.

I agree totally with you Adrian ?This is just an example what came out of the old WP Site. In this case the final result will just be surrounding div with a class. But The point is - how to catch the Text BETWEEN the tags and get rid of the end tag via Hanna Code.
To make it more clear:

[[av_textblock someAttributes]]
Some Text
[[/av_textblock]]


should go into something like this:
 

<div class="textblock">
Some Text
</div>

 

Link to comment
Share on other sites

Thanks for the reply Adrian. I'm understanding your example. This is how I do it usually myself. In my case the original markup comes from the wordpress import (and the original Wordpress shortcuts). So I wanted to deal with what I got. If Hanna Code doesn't support closing tags I eventually have to find another way to convert the imported posts to fit Hanna Code.

Link to comment
Share on other sites

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
×
×
  • Create New...