Keyword

Simple Image Gallery does not work in k2

More
12 years 10 months ago #91234 by matthew turner
Replied by matthew turner on topic Simple Image Gallery does not work in k2
Hi Jock,

Add me as a friend / PM me for more specifics...

Please Log in or Create an account to join the conversation.

More
12 years 10 months ago #91235 by Jock
Replied by Jock on topic Simple Image Gallery does not work in k2
Will do ...

Please Log in or Create an account to join the conversation.

More
12 years 10 months ago #91236 by Jock
Replied by Jock on topic Simple Image Gallery does not work in k2
So are you saying that you managed to enter this:

 

{gallery rows=3 cols=1 width=200 height=140 crop=1 labels=captions alignment=left orientation=horizontal buttons=0 links=0 counter=0 overlay=1}food/{/gallery}

 

Directly in the extra field and it worked? I've added you as a friend btw Mat.

 

Please Log in or Create an account to join the conversation.

More
12 years 10 months ago #91237 by matthew turner
Replied by matthew turner on topic Simple Image Gallery does not work in k2
Hi Jock,

Yes that plugin code worked in extrafields...

Please Log in or Create an account to join the conversation.

More
12 years 10 months ago #91238 by Rastislav Klc
Replied by Rastislav Klc on topic Simple Image Gallery does not work in k2
Hi guys,

there is so much stir in this topic that I would like to clarify the whole thing the way I understand it.


K2 is content component for Joomla. As such it brings its own handling of certain aspects of output and awesome templating techniques :) Therefore it does not necessary behaves exactly as original content in Joomla. Extra Fields, I think, were originally meant to simply enter some simple "extra" information that can be used in template .php file to user's liking. Extra Field does not necessary holds information that should be outputted DIRECTLY to the browser. It could be counter of some sort, it can be weight, color, age, etc. (value can be used as counter in cycles, path to file, extra configuration...). But also it can hold html code meant for output (ex: room description of hotel in my website).


So the information of what should happen with this Extra Field information is prescribed in .php template file. There is some default behavior which is written in bunch of default templates, for ex. in file:
components/com_k2/templates/default/item.php

However you should never touch this file. Therefore there is perfectly legitimate and advised way of customizing and overwriting this .php template file - which is essential to K2 templating. You can read details about K2 templating here simon.getk2.org/k2-documents/item/91-templating. Making long story short, for above file there should be this custom file that will handle representation of default item:
templates/YOUR_TEMPLATE/html/com_k2/default/item.php

This is not a hack, this is how it should be done and you are not touching core files, just customizing template.

 

So basically when you create template from scratch (or just copying and adjusting existing default template), you need to define how those Extra Fields will be handled. By default they are just plainly echoed for browser as name and value pair. See that original item.php file around line 255. However they are not scanned for {plugin} tags, therefore plugins are not recognized.

 

You can write your own template (or copy and adjust existing). There are basically 2 aproaches that come to my mind. Both will require to adjust for ex. this file
templates/YOUR_TEMPLATE/html/com_k2/default/item.php
and of course that template must be activated in Joomla backend. You do not have to build whole new template, neither your template will have to have all the template files, it is enough to copy and adjust just single file, rest of the template will automagically use default template provided by K2. So finaly here are two snipets that could be used in item.php custom template file:

 

1) Output all the extra fields in the same fashion as it was main content (example lacks any extra html formating):
<?php foreach ($this->item->extra_fields as $key=>$extraField): ?> <?php echo JHTML::_('content.prepare', $extraField->value); ?><?php endforeach; ?>

In this case you can write in any extra field html + any plugin with its crazy parameters and it will be outputed as expected. So you can enter in backend's extrafield something like this:
This is my gallery.
{gallery rows=3 cols=1 width=200 height=140 crop=1 labels=captions alignment=left orientation=horizontal buttons=0 links=0 counter=0 overlay=1}stories/brasil/{/gallery}
Pictures are showing my vacation in Brasil :)
 

2) There could be numerous cases when you decide that extrafield will hold just partial info (like path to the gallery). ex: first extrafield will be gallery description, second field path, etc. you get the idea:
<?php
$galleryDesc = $this->item->extra_fields[1]->value $galleryPath = $this->item->extra_fields[2]->value
echo
$galleryDesc .'<br />'
;
echo JHTML::_('content.prepare', '{gallery}' .
$galleryPath
.'
{/gallery}'
); ?>

So the difference is in designers mind. You just have to know what to expect in Extra Fields and prepare content according. then in .php template file put all the pieces together as you like.


This was exhausting post :)

 

PS: there couold be some syntax mishap, I did not test it, but sure the idea is right.

Please Log in or Create an account to join the conversation.

More
12 years 10 months ago #91239 by matthew turner
Replied by matthew turner on topic Simple Image Gallery does not work in k2
Hi Rastislav Klc,

Well written, and thanks for your post on Friday - I would still be looking for an answer if you had not posted!!

Please Log in or Create an account to join the conversation.

More
12 years 10 months ago #91240 by Jock
Replied by Jock on topic Simple Image Gallery does not work in k2
Rastislav Klc ... you my friend are an absolute legend. Just changing:

 

<?php echo $extraField->value; ?>

 

to this

 

<?php echo JHTML::_('content.prepare', $extraField->value); ?>

 

Makes it work ... amazing, such a simple solution yet I was looking everywhere for it!Also Mat ... many thanks for your help too

Please Log in or Create an account to join the conversation.

More
12 years 10 months ago #91241 by Rastislav Klc
Replied by Rastislav Klc on topic Simple Image Gallery does not work in k2
I am glad I could help

Please Log in or Create an account to join the conversation.

More
12 years 9 months ago #91242 by dompl
Replied by dompl on topic Simple Image Gallery does not work in k2
@Rastislav Klc, @mat, guys thank you so much for this solution. Works perfect! Thanks so much!

Please Log in or Create an account to join the conversation.

More
12 years 9 months ago #91243 by Odin Mayland
Replied by Odin Mayland on topic Simple Image Gallery does not work in k2
I agree.  

Why does code pasted into the K2item extra fields tab work but if you paste the same code into the K2 Extra Fields editor from the K2 dashboard, it does not work?
Jock said:

I Mat ... I appreciate your input.

 

Does this mean that there is no way you can change the K2 php code to get it to work with this kind of syntax. I struggle to understand why it works in the content editor but not in the extra fields? I would really rather avoid any such hacks ^

Please Log in or Create an account to join the conversation.


Powered by Kunena Forum