Jump to content

Hanna Code outputs complete body text


suntrop
 Share

Recommended Posts

I came across a strange problem on my site as I wanted to display a teaser of the latest news.

I've got this Hanna Code:

<?php $latestNews = $pages->find('tweet_page=1, check_access=0, sort=-created, limit=1')->first(); ?>
<?php if($latestNews) { ?>
	<div class="snippet-teaser clearfix">
		<h3><?php echo $latestNews->get("heading|title"); ?></h3>
		<p><?php echo substr(strip_tags( $latestNews->body ), 0, 40); ?>… <a href="/test/">more</a></p>
	</div>
<?php } ?>

I put my [[show-latest-news]] into my sidebar and instead of showing the title and 40 characters of the body the complete body gets outputted without any of the HTML around it. If I change it to truncate the title it works well. I also tried the same code in a template file (without Hanna Code) and the truncated body is displayed. Even the preview within the Hanna Code module displays the truncated body.

I can't think of where this error comes from. Why is it working from my template and with any other field but not with the body field?

Link to comment
Share on other sites

The body field is an CKEditor and it's the only one of its kind. But I have tested it on other fields like the title, the summary (textarea), categories (checkboxes) and two other text inputfields. None of them have this problem.

Link to comment
Share on other sites

What I was getting at is to test against a similar field, so in this case, a textarea field called "test" or whatever that uses CKEditor. It sounds to me like that is where the problem is originating from...That would help us narrow down where the problem is coming from...

Link to comment
Share on other sites

Good. We are getting closer. What is the exact name of your 'body' field (maybe not related but there was a problem with how some HCs were named; what is the name of your HC?). What version of Hanna Code are you using? The latest? Secondly, what are the settings you have in your CKEditor; did you use the same settings in the field you changed from TinyMCE?

Edited by kongondo
Link to comment
Share on other sites

I think it is the Hanna Code text formatter I have enabled for the body field.

I just enabled it for the other field and it outputs the complete body (instead of my truncated text). For the body field I cannot disabled it.

Seems I can't use the body variable inside a HC if the field uses HC itself. Once there is $var->body inside the HC it replaces everything else. I think I'll stick with just the title :-) That works.

Link to comment
Share on other sites

Hanna Code will not work without its text formatter :-). I don't know what set up you have there but like I said - I tested your code, and my code in a field called 'body' that uses CKEditor and it works just fine. Anyway, you seem to have got it sorted....

Link to comment
Share on other sites

I think it is the Hanna Code text formatter I have enabled for the body field.

I just enabled it for the other field and it outputs the complete body (instead of my truncated text). For the body field I cannot disabled it.

Seems I can't use the body variable inside a HC if the field uses HC itself. Once there is $var->body inside the HC it replaces everything else. I think I'll stick with just the title :-) That works.

I've had similar behavior when using a Hanna Code inside a field called 'body', which was a textarea with CKEditor. The page that had the Hanna Code on it, was listing a choice of it's children and subchildren, which also had the same body field. In my case i could not get the children body displayed via the Hanna.

I solved it by changing the body field on the children to a new similarly typed field, with a different name. At the time i didn't really give it a second thought because at that stage it was an easy change, but it's something to be aware of. I really don't know if this might be in the realm of bugs or if this makes total sense because of the way Hanna Code works, and if the Hanna you use does certain things.

Link to comment
Share on other sites

I just installed a new version and encounter the same problem. If the field (in my case 'body') has the Hanna Code Text Formatter enabled it'll replace everything with that field's content.

I think in your case you didn't had the Hanna Code Text Formatter active for your newly created field. But your body field had – thus you got the same error. At the weekend I have some time to check where this comes from. I don't think this is "normal" behavior.

Link to comment
Share on other sites

  • 2 months later...

I had a similar experience and found that this happens when HannaCode renders a field which again contains some HannaCode.

I submitted a patch to support recursive HannaCode to git. You could try out if it fixes your issue by replacing the TextformatterHannaCode.module file with the one in this fork:

https://github.com/hwmaier/ProcessHannaCode/blob/master/TextformatterHannaCode.module

  • 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
 Share

×
×
  • Create New...