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   1 member

  • Similar Content

    • By teppo
      This module tracks changes, additions, removals etc. of public (as in "not under admin") pages of your site. Like it's name says, it doesn't attempt to be a version control system or anything like that - just a log of what's happened.
      At the moment it's still a work in progress and will most likely be a victim of many ruthless this-won't-work-let's-try-that-instead cycles, but I believe I've nailed basic functionality well enough to post it here.. so, once again, I'll be happy to hear any comments you folks can provide
      https://modules.processwire.com/modules/process-changelog/
      https://github.com/teppokoivula/ProcessChangelog
      How does it work?
      Exactly like it's (sort of) predecessor, Process Changelog actually consists of two modules: Process Changelog and Process Changelog Hooks. Hooks module exists only to serve main module by hooking into various functions within Pages class, collecting data of performed operations, refining it and keeping up a log of events in it's own custom database table (process_changelog.) Visible part is managed by Process Changelog, which provides users a (relatively) pretty view of the contents of said log table.
      How do you use it?
      When installed this module adds new page called Changelog under Admin > Setup which provides you with a table view of collected data and basic filtering tools See attached screenshots to get a general idea about what that page should look like after a while.
      For detailed installation instructions etc. see README.md.
       


    • By Gadgetto
      Status update links (inside this thread) for SnipWire development will be always posted here:
      2019-08-08
      2019-06-15
      2019-06-02
      2019-05-25
      If you are interested, you can test the current state of development:
      https://github.com/gadgetto/SnipWire
      Please note that the software is not yet intended for use in a production system (alpha version).
      If you like, you can also submit feature requests and suggestions for improvement. I also accept pull requests.
      ---- INITIAL POST FROM 2019-05-25 ----
      I wanted to let you know that I am currently working on a new ProcessWire module that fully integrates the Snipcart Shopping Cart System into ProcessWire. (this is a customer project, so I had to postpone the development of my other module GroupMailer).
      The new module SnipWire offers full integration of the Snipcart Shopping Cart System into ProcessWire.
      Here are some highlights:
      simple setup with (optional) pre-installed templates, product fields, sample products (quasi a complete shop system to get started immediately) store dashboard with all data from the snipcart system (no change to the snipcart dashboard itself required) Integrated REST API for controlling and querying snipcart data webhooks to trigger events from Snipcart (new order, new customer, etc.) multi currency support self-defined/configurable tax rates etc. Development is already well advanced and I plan to release the module in the next 2-3 months.
      I'm not sure yet if this will be a "Pro" module or if it will be made available for free.
      I would be grateful for suggestions and hints!
      (please have a look at the screenshots to get an idea what I'm talking about)
       




    • By apeisa
      Update 31.7.2019: AdminBar is now maintained by @teppo. Modules directory entry has been updated, as well as the "grab the code" link below.
      ***
      Latest screencast: http://www.screencas...73-ab3ba1fea30c
      Grab the code: https://github.com/teppokoivula/AdminBar
      ***
      I put this Adminbar thingy (from here: http://processwire.c...topic,50.0.html) to modules section and to it's own topic.
      I recorded quick and messy screencast (really, my first screencast ever) to show what I have made so far. You can see it from here: http://www.screencas...18-1bc0d49841b4
      When the modal goes off, I click on the "dark side". I make it so fast on screencast, so it might seem a little bit confusing. Current way is, that you can edit, go back to see the site (without saving anything), continue editing and save. After that you still have the edit window, but if you click "dark side" after saving, then the whole page will be reloaded and you see new edits live.
      I am not sure if that is best way: there are some strengths in this thinking, but it is probably better that after saving there shouldn't be a possibility to continue editing. It might confuse because then if you make edits, click on dark side -> *page refresh* -> You lose your edits.
      ***
      When I get my "starting module" from Ryan, I will turn this into real module. Now I had to make some little tweaks to ProcessPageEdit.module (to keep modal after form submits). These probably won't hurt anything:
      if($this->redirectUrl) $this->session->redirect($this->redirectUrl); if(!empty($_GET['modal'])) $this->session->redirect("./?id={$this->page->id}&modal=true"); // NEW LINE else $this->session->redirect("./?id={$this->page->id}");   and...
      if(!empty($_GET['modal'])) { $form->attr('action', './?id=' . $this->id . '&modal=true'); } else { $form->attr('action', './?id=' . $this->id); // OLD LINE }  
    • By Mike Rockett
      Jumplinks for ProcessWire
      Release: 1.5.54
      Composer: rockett/jumplinks
      Jumplinks is an enhanced version of the original ProcessRedirects by Antti Peisa.
      The Process module manages your permanent and temporary redirects (we'll call these "jumplinks" from now on, unless in reference to redirects from another module), useful for when you're migrating over to ProcessWire from another system/platform. Each jumplink supports wildcards, shortening the time needed to create them.
      Unlike similar modules for other platforms, wildcards in Jumplinks are much easier to work with, as Regular Expressions are not fully exposed. Instead, parameters wrapped in curly braces are used - these are described in the documentation.
      Under Development: 2.0, to be powered by FastRoute
      As of version 1.5.0, Jumplinks requires at least ProcessWire 2.6.1 to run.
      View on GitLab
      Download via the Modules Directory
      Read the docs
      Features
      The most prominent features include:
      Basic jumplinks (from one fixed route to another) Parameter-based wildcards with "Smart" equivalents Mapping Collections (for converting ID-based routes to their named-equivalents without the need to create multiple jumplinks) Destination Selectors (for finding and redirecting to pages containing legacy location information) Timed Activation (activate and/or deactivate jumplinks at specific times) 404-Monitor (for creating jumplinks based on 404 hits) Additionally, the following features may come in handy:
      Stale jumplink management Legacy domain support for slow migrations An importer (from CSV or ProcessRedirects) Feedback & Feature Requests
      I’d love to know what you think of this module. Please provide some feedback on the module as a whole, or even regarding smaller things that make it whole. Also, please feel free to submit feature requests and their use-cases.
      Note: Features requested so far have been added to the to-do list, and will be added to 2.0, and not the current dev/master branches.
      Open Source

      Jumplinks is an open-source project, and is free to use. In fact, Jumplinks will always be open-source, and will always remain free to use. Forever. If you would like to support the development of Jumplinks, please consider making a small donation via PayPal.
      Enjoy! :)
×
×
  • Create New...