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 gebeer
      I am happy to present my new fieldtype FieldtypeImageFromPage. It is made up of 2 modules:
      Fieldtype Image Reference From Another Page is a Fieldtype that stores a reference to a single image from another page. The image can be selected with the associated Inputfield.
      Inputfield Select Image From Page is an Inputfield to select a single image from images on a predefined page and it's children.
      And there also is a helper module that takes care of cleanup tasks.
      This module evolved out of a discussion about my other Module FieldtypeImagePicker.  It caters for use cases where a set of images is being reused multiple times across a site. With this fieldtype these images can be administered through a chosen page. All images uploaded to that page will be available in the inputfield.
      When to use ?
      Let editors choose an image from a set of images that is being used site-wide. Ideal for images that are being re-used across the site.
      Suited for images that are used on multiple pages throughout the site (e.g. icons).
      Other than the native ProcessWire images field, the images here are not stored per page. Only references to images on another page are stored. This has several advantages:
      one central place to organize images when images change, you only have to update them in one place. All references will be updated, too. (Provided the name of the image that has changed stays the same) Features
      Images can be manipulated like native ProcessWire images (resizing, cropping etc.) Image names are fully searchable through the API Accidental image deletion is prevented. When you want to delete an image from one of the pages that hold your site-wide images, the module searches all pages that use that image. If any page contains a reference to the image you are trying to delete, deletion will be prevented. You will get an error message to help you edit those pages and remove references there before you can finally delete the image. How to install and setup
      Download and install this module like any other modules in ProcessWire Create a page in the page tree that will hold your images. This page's template must have an images field Upload some images to the page you created in step 2 Create a new field. As type choose 'Image Reference From Another Page'. Save the field. In 'Details' Tab of the field choose the page you created in step 2 Click Save button Choose the images field name for the field that holds your images (on page template from step 2) Click Save button again Choose whether you want to include child pages of page from step 2 to supply images Add the field to any template You are now ready to use the field View of the inputfield on the page edit screen:

      View of the field settings

      The module can be installed from this github repo. Some more info in the README there, too.
      In my tests it was fairly stable. After receiving your valued feedback, I will eventually add it to the modules directory.
      My ideas for further improvement:
      - add ajax loading of thumbnails
      Happy to hear your feedback!
       
    • By gebeer
      Although the PW backend is really intuitive, ever so often my clients need some assistance. Be it they are not so tech savvy or they are not working in the backend often.
      For those cases it is nice to make some help videos available to editors. This is what this module does.
      ProcessHelpVideos Module
      A Process module to display help videos for the ProcessWire CMS. It can be used to make help videos (screencasts) available to content editors.
      This module adds a 'Help Videos" section to the ProcessWire backend. The help videos are accessible through an automatically created page in the Admin page tree. You can add your help videos as pages in the page tree. The module adds a hidden page to the page tree that acts as parent page for the help video pages. All necessary fields and templates will be installed automatically. If there are already a CKEditor field and/or a file field for mp4 files installed in the system, the module will use those. Otherwise it will create the necessary fields. Also the necessary templates for the parent help videos page and it's children are created on module install. The module installs a permission process-helpvideos. Every user role that should have access to the help video section, needs this permission. I use the help video approach on quite a few production sites. It is stable so far and well received by site owners/editors. Up until now I installed required fields, templates and pages manually and then added the module. Now I added all this logic to the install method of the module and it should be ready to share.
      The module and further description on how to use it is available on github: https://github.com/gebeer/ProcessHelpVideos
      If you like to give it a try, I am happy to receive your comments/suggestions here.
    • By Robin S
      A module created in response to the topic here:
      Page List Select Multiple Quickly
      Modifies PageListSelectMultiple to allow you to select multiple pages without the tree closing every time you select a page.
      The screencast says it all:

       
      https://github.com/Toutouwai/PageListSelectMultipleQuickly
      https://modules.processwire.com/modules/page-list-select-multiple-quickly/
    • By gebeer
      Hello all,
      sharing my new module FieldtypeImagePicker. It provides a configurable input field for choosing any type of image from a predefined folder.
      The need for it came up because a client had a custom SVG icon set and I wanted the editors to be able to choose an icon in the page editor.
      It can also be used to offer a choice of images that are used site-wide without having to upload them to individual pages.
      There are no image manipulation methods like with the native PW image field.
      Module and full description can be found on github https://github.com/gebeer/FieldtypeImagePicker
      Kudos to @Martijn Geerts. I used his module FieldTypeSelectFile as a base to build upon.
      Here's how the input field looks like in the page editor:

      Hope it can be of use to someone.
      If you like to give it a try, I'm happy to hear your comments or suggestions for improvement. Eventually this will go in the module directory soon, too.
    • By bernhard
      @Sergio asked about the pdf creation process in the showcase thread about my 360° feedback/survey tool and so I went ahead and set my little pdf helper module to public.
      Description from PW Weekly:
       
      Modules Directory: https://modules.processwire.com/modules/rock-pdf/
      Download & Docs: https://github.com/BernhardBaumrock/RockPDF
       
      You can combine it easily with RockReplacer: 
      See also a little showcase of the RockPdf module in this thread:
       
×
×
  • Create New...