#1 2011-09-16 14:54:39

Davie
Member
Registered: 2011-05-24
Posts: 6

Content Elements - loop

Hi!

How to display all content elements with loop ?
What is the purpouse of using that functionality when i need to know their names in the view?
Can't understand what is this for?
It is like ferrari without wheels.

Offline

#2 2011-09-17 10:16:03

ukyo
Community Manager
From: Marmaris - Turkey
Registered: 2010-05-19
Posts: 629
Website

Re: Content Elements - loop

https://github.com/ionize/ionize/wiki/FAQ-%3A-Tags

<ion:elements type="article" name="your_element_name">
     <ion:field name="your_element_field" />
</ion:elements>

<ion:ukyo from="Turkey" />
User's documentation | Webdesigner's doc | Language files | My Github Repositories
Please send your first message to a forum section, not forum users or administration.

Offline

#3 2011-09-19 17:15:06

Davie
Member
Registered: 2011-05-24
Posts: 6

Re: Content Elements - loop

ukyo wrote:

https://github.com/ionize/ionize/wiki/FAQ-%3A-Tags

<ion:elements type="article" name="your_element_name">
     <ion:field name="your_element_field" />
</ion:elements>

Did you realy read and understand my question? or you like to copy paste ?
How to LOOOOOP all elements from a group?

Offline

#4 2011-09-19 18:45:39

ukyo
Community Manager
From: Marmaris - Turkey
Registered: 2010-05-19
Posts: 629
Website

Re: Content Elements - loop

Calm down @davie. I checked your question quickly. I wrote usage of content elements in FAQ Its not a copy / paste. I think @Michel-Ange will give you true answer!


<ion:ukyo from="Turkey" />
User's documentation | Webdesigner's doc | Language files | My Github Repositories
Please send your first message to a forum section, not forum users or administration.

Offline

#5 2011-09-19 18:49:37

thedoglett
Member
Registered: 2011-07-15
Posts: 128

Re: Content Elements - loop

I understand what Davie is asking - if I have a content element called 'Fred' which contains several entries 'Wilma', 'Barney' and 'Betty', he wants to display all of them without having to specifically reference them.

This is a good idea and something I'd like details on how to do, even better if possible to limit to a certain number returned (i.e. 3, 5 or 10).

Offline

#6 2011-09-19 19:33:32

ukyo
Community Manager
From: Marmaris - Turkey
Registered: 2010-05-19
Posts: 629
Website

Re: Content Elements - loop

You can check "application/libraries/Tagmanager/Element.php" maybe you can find your answer there!


<ion:ukyo from="Turkey" />
User's documentation | Webdesigner's doc | Language files | My Github Repositories
Please send your first message to a forum section, not forum users or administration.

Offline

#7 2011-09-19 20:24:23

thedoglett
Member
Registered: 2011-07-15
Posts: 128

Re: Content Elements - loop

Hmmm, problem is I'm no php expert and I'm really struggling to work out how to call it! Its there, in front of me, and I've been trying to get it work for the past two hours but I'm just not seeing it!

Are we talking something like...

<ion:elements type="article"  name="ElementName">
  <ion:fields />
</ion:elements>

or

<ion:elements type="article" >
  <ion:fields from="ElementName" limit="2" />
</ion:elements>

...because its not working for me!

Another clue/nudge please?! smile

Last edited by thedoglett (2011-09-19 22:53:00)

Offline

#8 2011-09-19 23:20:33

thedoglett
Member
Registered: 2011-07-15
Posts: 128

Re: Content Elements - loop

OK - I give up!

I've tried goodness knows how many permutations of from=, limit=, type=, the lot and I'm sure I'm missing something really simple but I can't figure it out for the life of me (as I said, I'm not a php guru, I only have a very basic grasp of it).

Can someone please explain to me how to loop through a content element I have called 'quotes' which has three fields in it so I can display each of them?

This is pretty urgent now so if its at all possible to give me an answer soon it would be appreciated!

Many thanks.

Offline

#9 2011-09-20 09:48:32

Davie
Member
Registered: 2011-05-24
Posts: 6

Re: Content Elements - loop

ukyo wrote:

Calm down @davie. I checked your question quickly. I wrote usage of content elements in FAQ Its not a copy / paste. I think @Michel-Ange will give you true answer!

I'm completly calm, please don't try to read state of mind from letters smile
When i check it all myself i leave a post. thx for now.

Offline

#10 2011-09-20 11:53:00

Davie
Member
Registered: 2011-05-24
Posts: 6

Re: Content Elements - loop

Hi again.

I found some interesting code inside Element.php

public static function tag_element_fields($tag)

This function should  return all elements but for me it looks unfinished.
There is no code to handle translations for example. (Look function above)
And no strings are returned.

My modified function looks now diffrent, it is not a beauty but it works

    public static function tag_element_fields($tag) {
        $element = $tag->locals->element;

        $str = '';
        if (!empty($element['fields'])) {
            foreach ($element['fields'] as $field) {

                $tag->locals->field = $field;

                if ($field['translated'] == '1') {
                    if (isset($field[Settings::get_lang('current')]['content'])) {
                        $field['label'] = $field[Settings::get_lang('current')]['label'];
                        $field['content'] = $field[Settings::get_lang('current')]['content'];
                        if ($field['content'])
                            $str .= $field['label'] . ' - ' . $field['content'] . '<br />';
                    }
                } else {
                    if ($field['content'])
                        $str .= $field['label'] . ' - ' . $field['content'] . '<br />';
                }
            }
        }
        return $str;
    }

Will display all elements , and if some are empty omits them.
Hope someone cleans the code a little and make it even better.


OMG i came to another problem labels are NOT translated.
anyone have idea to enable translation of labels.
Database will not allow me to do that i thnik.

Last edited by Davie (2011-09-20 12:08:16)

Offline

#11 2011-09-20 12:50:26

ukyo
Community Manager
From: Marmaris - Turkey
Registered: 2010-05-19
Posts: 629
Website

Re: Content Elements - loop

Labels not for multilang websites! Normally labels for "Admin Panel".

if you use content elements like this codes:

<ul>
<ion:elements type="article" name="your_element_name">
     <li><strong><ion:translation term="my_element_field_title_1" /> :</strong> <ion:field name="your_element_field_1" /><li>
     <li><strong><ion:translation term="my_element_field_title_2" /> :</strong> <ion:field name="your_element_field_2" /><li>
     <li><strong><ion:translation term="my_element_field_title_3" /> :</strong> <ion:field name="your_element_field_3" /><li>
</ion:elements>
</ul>

you can manage content elements much better. you can apply styles etc. This is my idea!


<ion:ukyo from="Turkey" />
User's documentation | Webdesigner's doc | Language files | My Github Repositories
Please send your first message to a forum section, not forum users or administration.

Offline

#12 2011-09-20 17:30:29

thedoglett
Member
Registered: 2011-07-15
Posts: 128

Re: Content Elements - loop

@ukyo - doesn't your method involve specifying exactly which fields from a content element you want to display rather than just displaying all fields within a content element?

Surely there must be a way to list all fields in a specific content element in a way similar to the following?

<ion:elements type="article" >
  <ion:fields from="ElementName" limit="2" />
</ion:elements>

Last edited by thedoglett (2011-09-20 17:42:51)

Offline

#13 2011-09-20 18:16:58

ukyo
Community Manager
From: Marmaris - Turkey
Registered: 2010-05-19
Posts: 629
Website

Re: Content Elements - loop

How will you appy style for your element fields? Will you edit "Element.php"? For make custom style?


<ion:ukyo from="Turkey" />
User's documentation | Webdesigner's doc | Language files | My Github Repositories
Please send your first message to a forum section, not forum users or administration.

Offline

#14 2011-09-20 18:34:47

thedoglett
Member
Registered: 2011-07-15
Posts: 128

Re: Content Elements - loop

I was thinking of using the tag="" method as it works with the normal ion:field manner - like this:

<ion:elements type="article" >
  <ion:fields from="ElementName" limit="2" tag="blockquote" />
</ion:elements>

This would loop through all fields from ElementName and return them in a (in this example) blockquote tag.

To clarify what I'm doing in this instance, I'm pulling several customer quotes (field 1 = "fantastic service...", field 2 = "friendly staff.." etc) from a content element called "CustomerQuotes" which when returned will each be wrapped in a blockquote tag which will be styled via css. I hope that makes sense.

Last edited by thedoglett (2011-09-20 19:25:47)

Offline

#15 2011-09-20 18:56:10

ukyo
Community Manager
From: Marmaris - Turkey
Registered: 2010-05-19
Posts: 629
Website

Re: Content Elements - loop

Element.php need ionize core team edit for your needs! Core team could give true answer for content elements!


<ion:ukyo from="Turkey" />
User's documentation | Webdesigner's doc | Language files | My Github Repositories
Please send your first message to a forum section, not forum users or administration.

Offline

#16 2011-09-20 19:25:25

thedoglett
Member
Registered: 2011-07-15
Posts: 128

Re: Content Elements - loop

Calling the core team - we need you!

Last edited by thedoglett (2011-09-20 23:36:59)

Offline

#17 2011-09-22 22:35:32

Michel-Ange
Ionize Core Team
From: Paris, France
Registered: 2010-03-22
Posts: 713
Website

Re: Content Elements - loop

@Core Team !!! Wake up !
Where is the core team ? Sleeping ???

OK, guys, we will have a deeper look on that !


Inspiration & Innovation : Websites by Partikule, Agence Web Paris

Offline

#18 2011-09-22 22:46:36

thedoglett
Member
Registered: 2011-07-15
Posts: 128

Re: Content Elements - loop

Thanks Michel. At the same time, it may be an idea to include ordering - so either ascending, descending or (drum roll...) random!

<ion:elements type="article" >
  <ion:fields from="ElementName" limit="5" order="random" tag="blockquote" />
</ion:elements>

Random would enable you to pul a certain number of fields into your layout but in a random order - that way you don't have fields appearing in the same order on each page (so your home page will show fields 1, 5 and 10 whilst your contact page may show 7, 18 and 12).

Offline

#19 2011-09-23 01:43:57

Michel-Ange
Ionize Core Team
From: Paris, France
Registered: 2010-03-22
Posts: 713
Website

Re: Content Elements - loop

@Davie : Unfortunately not the good way...

It must be possible to separate the field label from its content.
Tags are done for that, to atomize data as it should.

But no stress, the asked feature is ready to be launched (on GitHub, official in 0.9.8 as it alter one table and adds another table)


Inspiration & Innovation : Websites by Partikule, Agence Web Paris

Offline

#20 2011-09-23 03:33:04

Michel-Ange
Ionize Core Team
From: Paris, France
Registered: 2010-03-22
Posts: 713
Website

Re: Content Elements - loop

It is now possible to edit / display the label of each field, translated.
Same for the element title.

Installation (from 0.9.7)

1. Backup your database.
2. Make the test first locally or on a dev server.
3. Execute this code on your DB : 

            CREATE TABLE IF NOT EXISTS element_definition_lang (
              id_element_definition int(11) unsigned NOT NULL,
              lang varchar(3) NOT NULL,
              title varchar(255) NOT NULL default '',
              PRIMARY KEY  (id_element_definition, lang)
            ) ENGINE=InnoDB  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='0.9.7';

        insert into extend_field_lang select id_extend_field, lang, label from extend_field, lang;

        ALTER TABLE `extend_field` DROP `label`;

Update to the last Git version : https://www.github.com/ionize/ionize/

If you want to manually update, the modified files are :

/application/controller/admin :
- element.php
- element_definition.php
- element_field.php
- extend_field.php

/application/libraries/Tagmanager :
- Element.php

/application/models/ :
- element_model.php
- extend_field_model.php

/themes/admin/views :
- element_definition.php
- element_detail.php
- element_field.php
- extend_field.php

Usage :

In this example, I've created one Element with the name "concert".
The title of the element is available for each element through the <ion:attribute name="title" /> tag.

In this example, I created one field "date" in the element "concert".
For each field, we can display the label, in each language.

<ion:elements type="concert">

        <ion:attribute name="name" />
        <ion:attribute name="title" />
    
        <ion:fields>
            
            <ion:attribute name="name" />
            <ion:attribute name="label" />
            <ion:attribute name="content" />
            
            <!-- Same as <ion:attribute name="content" /> -->
            <ion:field name="date" />
            
        </ion:fields>

</ion:elements>

@thedoglett : For the moment, the Content Elements don't have a parent context, but only one parent.
In other words, one Content Element cannot be linked to 2 parents at the same time.
What you ask about order will need to add context for Content Elements.

That's possible, we're thinking to something like that, but not for the next weeks.


Inspiration & Innovation : Websites by Partikule, Agence Web Paris

Offline

#21 2011-09-23 14:49:41

thedoglett
Member
Registered: 2011-07-15
Posts: 128

Re: Content Elements - loop

Thanks for getting back to me Michel, I was just thinking if it worked similarly to how you display articles for the blog (i.e. showing several child articles from a page = showing several fields from a content element) it would be quite handy. Will be interesting to see what's in the next release.

Offline

#22 2011-10-25 15:10:25

Davie
Member
Registered: 2011-05-24
Posts: 6

Re: Content Elements - loop

Michel-Ange - thanks a lot !!! superb i'm already using this feature and have a big banana on my face.
Keep up the good work.

Offline

What's Ionize ?

Ionize is an Open Source Content Management System created by webdesigners for webdesigners.

Created and maintained by Partikule and Toopixel , Ionize wants to be the easiest and most powerful CMS.

Can I help ?

Because talent is nothing without involvement, we are looking for motivated coders and webdesigners to join the project team.

Resources

Website : www.ionizecms.com
Documentation : doc.ionizecms.com

Development : Ionize on GitHub
Translations : Translations on GitHub