Jump to content
ryan

Hanna Code

Recommended Posts

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

Share this post


Link to post
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);

 

Share this post


Link to post
Share on other sites

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.)

Share this post


Link to post
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

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

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 ?

Share this post


Link to post
Share on other sites
[[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.

Share this post


Link to post
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>

 

Share this post


Link to post
Share on other sites

My example shows how you can do that with Hanna - you need to do something like define the value of a text variable within the hanna. They are self closing tags. There is no separate hanna close tag.

  • Like 1

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

Yeah, a little bit of regex magic should take care of that for you.

  • Like 1

Share this post


Link to post
Share on other sites

Thanks mr-fan and Adrian. In case it's useful for someone, here is how I solved the problem. In fact I did not use Hanna Code in the end but some regex stuff, together with Adrians AdminActions Module (great work btw). I think this way you can convert any type of wordpress shortcuts to cleaner Hanna Code, get rid of not needed attributes or convert shortcuts to HTML.

Example: I wanted to convert this:

[av_image src='https://www.domain.de/link/to/image.jpg' attachment_size='large' align='center' lot_more='attributes'][/av_image]

to a regular img tag. So I used a regular expression like this one:

/\[av_image.*src='([^']*)([^\]]*)\]\[/av_image\]/

to match my shortcodes via the search and replace Action in AdminActions Module and replaced it with something like that:

<img src="$1">

Which leads to an ordinary image Tag. $1 stands for the first group which is the src attribute. With variations of this you can convert nearly everything. But if you're not familiar with regex (like me) it can be very tricky. Database restore feature of AdminActions Module saved me some times 😉  For testing and learning I used this tool which helped me a lot in creating the regex Expressions: https://www.phpliveregex.com/

 

  • Like 1

Share this post


Link to post
Share on other sites

Hello there.

I am working on a project and decided to try out Hanna Code tags to insert some custom HTML markup. The problem is that the markup includes some PHP variables to be checked and inserted at some spots. If I tell Hanna that the code is HTML, the php is just echoed and not processed. If I set the code as PHP, then my HTML is causing errors (of course).

So is it possible/wise to mix HTML and PHP inside of Hanna Code tags and if yes, how can I achieve that? 

Any examples of how to use HTML & PHP inside a single tag would be great.

Share this post


Link to post
Share on other sites

If you set the HC to PHP, you would have to echo your HTML of course, or concatenate and then echo it.

<?php

$out .= '<div class="seo-block seo-interviews">';
$out .= "<h2>{$heading}</h2>";
$out .= '<ul>';
foreach( $interviews as $one ){
  $out .= "<li>
   // ...
  </li>";
}
$out .= '</ul>';
$out .= '</div>';
echo $out;

 

  • Like 2
  • Thanks 1

Share this post


Link to post
Share on other sites

Hey @Klenkes I always get lazy which was the reason to search for a way to include only the PHP particles in my HTML. I came to the same conclusion as your suggestion, however, this morning. Thank you for it. I guess that for a big chunk of markup the mix of HTML and PHP would not make it read-friendly so I will bang it with PHP.

Share this post


Link to post
Share on other sites

You could try using a PHP hannacode with:

?>
<html>test</html>
<?php

 

  • Like 1
  • Thanks 1

Share this post


Link to post
Share on other sites
Posted (edited)

Thanks @LostKobrakai I will try both suggestions and see which one would be easier for me, fit better and most important, would be good to read. It might be a bit harder to turn the entire code to pure PHP due to the fact that there will be lots of html code to assign to $out and to align it, however I might not worry about it as I am planning to minify pages anyway. The more I touch HC, the more ways I see to use it where some user intervention is required but no manual file editing is a good idea.

P.S. I tested @LostKobrakai suggestion and can confirm that it works 100% with escaping the PHP tag at the beginning and then adding the HTML code. In my scenario there would be lots of interactions with the HC parameters which would be a part of a few selectors so it would make more sense to have them in PHP. At least if anyone is looking for HTML and PHP mix inside a Hanna Code tags, they could use either approach.

Edited by MilenKo
Tested the @LostKobrakai suggestion and confirmed it is working
  • Like 1

Share this post


Link to post
Share on other sites

Just to mention for anyone coming across an issue using Hanna code blocks and having a <p>&nbsp;</p> which might mess up with the markup - it is not related to the module in any case but to the configuration of the field. I am not going to go to many details as there are quite a few topics that I've seen discussing it on other matters, so you could just find the best settings by changing the Text formatters, Content type and Beautify Markup Toggles (in my scenario, I removed empty paragraph tags and removed also non-breaking spaces.

Share this post


Link to post
Share on other sites

Hey all. While playing with Hanna Code module I need to set some attributes to not be allowed to be empty (category name or some page listing counts). I know that in the markup I can check for those, however I would like to know is there any way to set the status of the attributes from the HC admin and eliminate the need of adding extra checks for that?

What I am trying to achieve is to have a custom tag inserting a block with page listings from different categories. Then I assign the list of the categories to an array to place them in the markup so I would like to restrict empty values from the attributes options shown in Hanna Dialogues.

P.S. In some cases some values defined in the attributes might be needed to be validated before they are submitted to the tag call for further verification (some numbers needing to be null, not null, bigger/smaller than..., required etc.) So far I was able to set the attributes I need, however the question is how can I achieve some initial validation before they values are passed to the module for processing (during submission or during save).

Share this post


Link to post
Share on other sites

@MilenKo, just a quick note that I've merged your thread into the existing Hanna Code module support thread.

When you have questions regarding an existing module, please post them to the dedicated support thread (if one is available – you can find a link to the support thread from the Modules Directory entry for the module in question). Modules/Plugins area of the forum is intended for module-specific support threads, and there should be only one thread for each module. Thanks! 🙂

Share this post


Link to post
Share on other sites

@teppo no problem. That is usually what I do but maybe I've over drank the coffee and got too much coding that day 😉 

P.S. I kind of completted my task by adding some checks in the code but it would be useful to know if I can add some checks before submitting the values of parameters to Hanna Code. Maybe I should check with @Robin S as he is the developer of HC Dialogues and it seems like the module addition could be easier to manupulate.

 

 

  • Like 1

Share this post


Link to post
Share on other sites

Can I use Hanna Code in any field? Even a page title, or the title of a repeater? 

I have a site where someone wants to replace a snippet of text with an image wherever it appears, body, title, other text fields etc. - thinking this might be suitable.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Robin S
      Repeater Images
      Adds options to modify Repeater fields to make them convenient for "page-per-image" usage. Using a page-per-image approach allows for additional fields to be associated with each image, to record things such as photographer, date, license, links, etc.
      When Repeater Images is enabled for a Repeater field the module changes the appearance of the Repeater inputfield to be similar (but not identical) to an Images field. The collapsed view shows a thumbnail for each Repeater item, and items can be expanded for field editing.
      Screencast

      Installation
      Install the Repeater Images module.
      Setup
      Create an image field to use in the Repeater field. Recommended settings for the image field are "Maximum files allowed" set to 1 and "Formatted value" set to "Single item (null if empty)". Create a Repeater field. Add the image field to the Repeater. If you want additional fields in the Repeater create and add these also. Repeater Images configuration
      Tick the "Activate Repeater Images for this Repeater field" checkbox. In the "Image field within Repeater" dropdown select the single image field. You must save the Repeater field settings to see any newly added Image fields in the dropdown. Adjust the image thumbnail height if you want (unlike the core Images field there is no slider to change thumbnail height within Page Edit). Note: the depth option for Repeater fields is not compatible with the Repeater Images module.
      Image uploads feature
      There is a checkbox to activate image uploads. This feature allows users to quickly and easily add images to the Repeater Images field by uploading them to an adjacent "upload" field.
      To use this feature you must add the image field selected in the Repeater Images config to the template of the page containing the Repeater Images field - immediately above or below the Repeater Images field would be a good position.
      It's recommended to set the label for this field in template context to "Upload images" or similar, and set the visibility of the field to "Closed" so that it takes up less room when it's not being used. Note that when you drag images to a closed Images field it will automatically open. You don't need to worry about the "Maximum files allowed" setting because the Repeater Images module overrides this for the upload field.
      New Repeater items will be created from the images uploaded to the upload field when the page is saved. The user can add descriptions and tags to the images while they are still in the upload field and these will be retained in the Repeater items. Images are automatically deleted from the upload field when the page is saved.
      Tips
      The "Use accordion mode?" option in the Repeater field settings is useful for keeping the inputfield compact, with only one image item open for editing at a time. The "Repeater item labels" setting determines what is shown in the thumbnail overlay on hover. Example for an image field named "image": {image.basename} ({image.width}x{image.height})  
      https://github.com/Toutouwai/RepeaterImages
      https://modules.processwire.com/modules/repeater-images/
    • By EyeDentify
      Hello There Guys.

      I am in the process of getting into making my first modules for PW and i had a question for you PHP and PW gurus in here.

      I was wondering how i could use an external library, lets say TwitterOAuth in my PW module.
      Link to library
      https://twitteroauth.com/

      Would the code below be correct or how would i go about this:
      <?PHP namespace ProcessWire; /* load the TwitterOAuth library from my Module folder */ require "twitteroauth/autoload.php"; use Abraham\TwitterOAuth\TwitterOAuth; class EyeTwitter extends WireData,TwitterOAuth implements Module { /* vars */ protected $twConnection; /* extend parent TwitterOAuth contructor $connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $access_token, $access_token_secret); */ public function myTwitterConnection ($consumer_key, $consumer_secret, $access_token, $access_token_secret) { /* save the connection for use later */ $this->twConnection = TwitterOAuth::__construct($consumer_key, $consumer_secret, $access_token, $access_token_secret); } } ?> Am i on the right trail here or i am barking up the wrong tree?
      I don´t need a complete solution, i just wonder if i am including the external library the right way.
      If not, then give me a few hint´s and i will figure it out.

      Thanks a bunch.

      /EyeDentify
    • By dimitrios
      Hello,
      this module can publish content of a Processwire page on a Facebook page, triggered by saving the Processwire page.
      To set it up, configure the module with a Facebook app ID, secret and a Page ID. Following is additional configuration on Facebook for developers:
      Minimum Required Facebook App configuration:
      on Settings -> Basics, provide the App Domains, provide the Site URL, on Settings -> Advanced, set the API version (has been tested up to v3.3), add Product: Facebook Login, on Facebook Login -> Settings, set Client OAuth Login: Yes, set Web OAuth Login: Yes, set Enforce HTTPS: Yes, add "http://www.example.com/processwire/page/" to field Valid OAuth Redirect URIs. This module is configurable as follows:
      Templates: posts can take place only for pages with the defined templates. On/Off switch: specify a checkbox field that will not allow the post if checked. Specify a message and/or an image for the post.
      Usage
      edit the desired PW page and save; it will post right after the initial Facebook log in and permission granting. After that, an access token is kept.
       
      Download
      PW module directory: http://modules.processwire.com/modules/auto-fb-post/ Github: https://github.com/kastrind/AutoFbPost   Note: Facebook SDK for PHP is utilized.


    • By kongondo
      FieldtypeRuntimeMarkup and InputfieldRuntimeMarkup
       
      Modules Directory: http://modules.processwire.com/modules/fieldtype-runtime-markup/
      GitHub: https://github.com/kongondo/FieldtypeRuntimeMarkup
      As of 11 May 2019 ProcessWire versions earlier than 3.x are not supported
      This module allows for custom markup to be dynamically (PHP) generated and output within a page's edit screen (in Admin).
       
      The value for the fieldtype is generated at runtime. No data is saved in the database. The accompanying InputfieldRuntimeMarkup is only used to render/display the markup in the page edit screen.
       
      The field's value is accessible from the ProcessWire API in the frontend like any other field, i.e. it has access to $page and $pages.
       
      The module was commissioned/sponsored by @Valan. Although there's certainly other ways to achieve what this module does, it offers a dynamic and flexible alternative to generating your own markup in a page's edit screen whilst also allowing access to that markup in the frontend. Thanks Valan!
       
      Warning/Consideration
      Although access to ProcessWire's Fields' admin pages is only available to Superusers, this Fieldtype will evaluate and run the custom PHP Code entered and saved in the field's settings (Details tab). Utmost care should therefore be taken in making sure your code does not perform any CRUD operations!! (unless of course that's intentional) The value for this fieldtype is generated at runtime and thus no data is stored in the database. This means that you cannot directly query a RuntimeMarkup field from $pages->find(). Usage and API
       
      Backend
      Enter your custom PHP snippet in the Details tab of your field (it is RECOMMENDED though that you use wireRenderFile() instead. See example below). Your code can be as simple or as complicated as you want as long as in the end you return a value that is not an array or an object or anything other than a string/integer.
       
      FieldtypeRuntimeMarkup has access to $page (the current page being edited/viewed) and $pages. 
       
      A very simple example.
      return 'Hello'; Simple example.
      return $page->title; Simple example with markup.
      return '<h2>' . $page->title . '</h2>'; Another simple example with markup.
      $out = '<h1>hello '; $out .= $page->title; $out .= '</h1>'; return $out; A more advanced example.
      $p = $pages->get('/about-us/')->child('sort=random'); return '<p>' . $p->title . '</p>'; An even more complex example.
      $str =''; if($page->name == 'about-us') { $p = $page->children->last(); $str = "<h2><a href='{$p->url}'>{$p->title}</a></h2>"; } else { $str = "<h2><a href='{$page->url}'>{$page->title}</a></h2>"; } return $str; Rather than type your code directly in the Details tab of the field, it is highly recommended that you placed all your code in an external file and call that file using the core wireRenderFile() method. Taking this approach means you will be able to edit your code in your favourite text editor. It also means you will be able to type more text without having to scroll. Editing the file is also easier than editing the field. To use this approach, simply do:
      return wireRenderFile('name-of-file');// file will be in /site/templates/ If using ProcessWire 3.x, you will need to use namespace as follows:
      return ProcessWire\wireRenderFile('name-of-file'); How to access the value of RuntimeMarkup in the frontend (our field is called 'runtime_markup')
       
      Access the field on the current page (just like any other field)
      echo $page->runtime_markup; Access the field on another page
      echo $pages->get('/about-us/')->runtime_markup; Screenshots
       
      Backend
       

       

       
      Frontend
       

×
×
  • Create New...