LostKobrakai Posted February 6, 2015 Posted February 6, 2015 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; ?>
Peter Knight Posted February 6, 2015 Posted February 6, 2015 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
LostKobrakai Posted February 6, 2015 Posted February 6, 2015 Does it show "It' s 1 teams." ? Or does it even show this line? I'm just curious if the culpit is somehow in the foreach loop or earlier in loading $teams.
Peter Knight Posted February 6, 2015 Posted February 6, 2015 Your code outputs It's 9 teams ...which is the correct amount BTW
LostKobrakai Posted February 6, 2015 Posted February 6, 2015 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.
Macrura Posted February 6, 2015 Posted February 6, 2015 does team body have hanna code formatter enabled? 1
Peter Knight Posted February 6, 2015 Posted February 6, 2015 does team body have hanna code formatter enabled? Yes. One of the first things I checked too after making that error last time I'm going to deconstruct things tomorrow. Start off with calling just a single field in a basic template. Will report back
Macrura Posted February 6, 2015 Posted February 6, 2015 does it work if you disable the hanna code on that? i'm guessing from what you are saying, no...
hwmaier Posted February 7, 2015 Posted February 7, 2015 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. 4
LostKobrakai Posted February 7, 2015 Posted February 7, 2015 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. 3
Peter Knight Posted March 2, 2015 Posted March 2, 2015 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.
hwmaier Posted March 2, 2015 Posted March 2, 2015 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
Peter Knight Posted March 2, 2015 Posted March 2, 2015 Should clarify that removing the body field worked. I wasn't sure how to get your own github version running. Tried manually adding your changes and that didn't work.
gerritvanaaken Posted March 11, 2015 Posted March 11, 2015 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"? 1
LostKobrakai Posted March 11, 2015 Posted March 11, 2015 Have a look at this pull request: https://github.com/ryancramerdesign/ProcessHannaCode/pull/10
gerritvanaaken Posted March 11, 2015 Posted March 11, 2015 Wow, thanks, will have a try. Will report here if it works! –––– works as exspected!
thoha Posted March 23, 2015 Posted March 23, 2015 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
cstevensjr Posted March 23, 2015 Posted March 23, 2015 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: The code is working or is there something else you actually meant? 1
thoha Posted March 23, 2015 Posted March 23, 2015 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 1
naldrocks98 Posted June 16, 2015 Posted June 16, 2015 Question? Is it possible within a certain hanna code there is also a hanna code include...?
LostKobrakai Posted June 16, 2015 Posted June 16, 2015 Recursive hanna codes is mentioned already a few time in this topic. There's an open pull request on the github repo, that adds support for that, but the official release doesn't have that right now.
Marty Walker Posted June 22, 2015 Posted June 22, 2015 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.
alan Posted July 2, 2015 Posted July 2, 2015 (edited) 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 July 2, 2015 by alan
Macrura Posted July 2, 2015 Posted July 2, 2015 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. 1
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now