Jump to content

Hanna Code


ryan

Recommended Posts

One thing I noticed, I think there should be a space after "echo". Also I'm personally not keen on multiline strings. I don't trust them to work. I've also added a test for how much teams are really found, which is what I would check first. If there are multiple teams found, but only one is displayed you can say for sure somethings wrong with your snippet.

<?php
$teams = $pages->find("template=team_member,limit=10");
// Just for debug purposes
echo "It's ".count($teams)." teams.";
$out = "";
foreach ($teams as $team) {
  $out .= "<div class=\"team-wrapper\">";
  $out .= "<h2>{$team->title}</h2>";
  $out .= "<h3>{$team->team_role}</h3>";
  $out .= $team->body;
  $out .= "</div>";
}
echo $out;
?>
Link to comment
Share on other sites

That correctly displays within HannaCode itself (Save and Test) and counts 9 teams.

Once the HC tag is added to the Body field, I get a single team biography. No name or job role either.

One thing I noticed, I think there should be a space after "echo". Also I'm personally not keen on multiline strings. I don't trust them to work. I've also added a test for how much teams are really found, which is what I would check first. If there are multiple teams found, but only one is displayed you can say for sure somethings wrong with your snippet.

$out = "";
foreach ($teams as $team) {
  $out .= 
?>

I've seen this on peoples code samples before and always wondered why they were using this. Thanks for the tip :)

Link to comment
Share on other sites

So it seems the culpit is somewhere in the foreach loop, which is not what I expected :) Did you try the ultra failsave of using concatination instead of curly braces and single quotes for the class? I really don't see an error, but just to try it. Maybe var_dump $teams / $team inside of the loop, so check if something is messing with them.

Link to comment
Share on other sites

If {team->body} has hanna code formatter enabled, then it will not work as Hanna Code 1.9 does not support recursive Hanna code processing. Refer to my earlier post.

Remove the {$team->body} statement from your code snippet and check the result whether it then outputs all 9 members. Once you see that working, try using the patched version of Hanna Code I submitted on Github.

  • Like 4
Link to comment
Share on other sites

I've a feature request. As I can assign users of ProcessWire the right to view/list hanna codes it would be nice to be able to incorporate a description field, where I can add small explanations for each code. This way the list/view permission would be more useful on it's own. 

This could maybe later be incorporated in something like a small dropdown underneath hanna code textfields.

post-874-0-27543700-1423327850_thumb.jpg

  • Like 3
Link to comment
Share on other sites

  • 4 weeks later...

If {team->body} has hanna code formatter enabled, then it will not work as Hanna Code 1.9 does not support recursive Hanna code processing. Refer to my earlier post.

Remove the {$team->body} statement from your code snippet and check the result whether it then outputs all 9 members. Once you see that working, try using the patched version of Hanna Code I submitted on Github.

Hey hwmaler

That works so I can confirm it's an issue with recursive Body fields.

Link to comment
Share on other sites

That works so I can confirm it's an issue with recursive Body fields.

Peter,

Thanks for testing and confirming the fix. I will add your confirmation to the Github issue list notes and hopefully this fix is adopted at some stage by Ryan into the main release.

Henrik

Link to comment
Share on other sites

  • 2 weeks later...

I use PHP-based Hanna Code snippets for embedding certain fields from certain pages on other pages. Now I stumbled upon the fact that you cannot render fields within a Hanna Code when the Hanna Code Textformatter is applied to that field. The result is a broken output where only a small part of the page is being rendered.

How can I achieve those "recursive Hanna Codes"?

kmkmUQY.jpg

  • Like 1
Link to comment
Share on other sites

  • 2 weeks later...

Hi all,

if I write the following code in one of my template files:

$result = $db->query("SELECT id, name FROM pages");
while($row = $result->fetch_array()) print_r($row); 

It works and prints a list of all my pages.

If I write the same code in a "php hanna code", I get no result from the query.
Is there any reason, that $db is not working in hanna codes?

thanx for your help 
/thomas

Link to comment
Share on other sites

I took your code and created a php Hanna Code from it.  I created a template (clone of basic-page) and renamed it "test1".  The body field has the hanna code text formatter assigned to it.  Here is a sample of the output:

post-756-0-50646200-1427108827_thumb.png

The code is working or is there something else you actually meant?

  • Like 1
Link to comment
Share on other sites

Thank you cstenvsjr,

that was the output I want to see.
Now that I saw that it was no hanna problem, I found the solution. There was a little include(..) before the posted lines that was responsible for the error.

you made my day
/thomas

  • Like 1
Link to comment
Share on other sites

  • 2 months later...

I'm trying to use this simple hanna code in a CKEditor field (using PW 2.6.1):

<?php
	echo "<ul>";
	foreach ($pages->get('/contact-us/')->children as $offices) {
		echo "<li><h2>{$offices->title}</h2>{$offices->body}</li>";
	}
	echo "</ul>";

The 'contact-us' page has 4 child pages with the office info. If I add the above code to my template it works fine but if I add the HC to my body field it strips most of the content from that body field out. The only textformatter I have on that body field is the HC one. The 'Save & Test' shows the results fine so I have no idea what I'm doing wrong.

edit: for some reason if I remove the '$offices->body' from my echo it works.

edit 2: just read the previous pages and realise now it's a bug.

Link to comment
Share on other sites

  • 2 weeks later...

Sorry folks if I missed this in the docs and threads.., but is there a way to get a regular PW template to o/p a Hanna, sort of like a Hanna being an include?

$out .= "<div id='clientCard'>";
	$out .= "<h2>Client card</h2>";
	$out .= wire('modules')->get('[[client_card_intro]]');
$out .= "</div>";

I am trying to see if I can do this so I can build a DRY (don't repeat yourself) collection of items that I can use either in the Admin in a rich text field via the usual [[the_name_of_the_hanna]] or from the API in a template via a correct version of the code above.

Thanks for any comments, cheers, -Alan

Edit:

It looks as if Ryan recommends this is not done (if I read this right) for reasons of security.

Edited by alan
Link to comment
Share on other sites

yup, just include the path to the php file in your hanna code;

<?php

include($config->paths->templates . "hannas/myhanna.php");

then you can include that same file form a template, or use as hanna code.

  • Like 1
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...