Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
ItemManager 2.0
#26
USING IM’S TEMPLATE ENGINE

This is a basic tutorial on how to use ItemManager’s templates to customize the output of your item data. We will create an extremely simple single item view. That will be sufficient to cover the most important basics of using ItemManager’s external templates. This instruction is just for reference and do not cover all the template engine functions available in ItemManager. Goodluck!

Demo: http://im.ehret-studio.com/

First, create a new category named Illustrations and define the following fields for it.
Editor field, name: description
Field for image upload, name: images


Next, create a new item named Medical illustrations, check Enabled checkbox, enter your item description and upload some pictures of your choice:
[Image: illu_item.png?dl=0]


Now you may create a new theme directory named imtest, or use already existing theme, with 2 subdirectories css/ and tpl/:

[Image: dir_tree.jpg?dl=0]

The tpl/ directory contains all of the template (.tpl) files that ItemManager interacts with. The template files contains standard HTML and a set of predefined tags/placeholders surrounded by brackets [[ tag_name ]], that are populated with item specific data at runtime.

All template file names consists of several nodes: 1. Actual name, 2. The name of the library and the im.tpl extension. The separate node names are separated from each other by dots.
Example: name.library.im.tpl

In this tutorial you will use a total of three different template files:
  1. tpl/image.illustration.im.tpl
  2. tpl/trigger.illustration.im.tpl
  3. tpl/wrapper.illustration.im.tpl
The final markup is composed of three elements (your templates) shown on the picture below:

[Image: markup.jpg?dl=0]


1. image.illustration.im.tpl - template contains <img> tag surrounded by <li> tags.

Code:
<li><img alt="[[ title ]]" src="[[ src ]]"></li>



2. trigger.illustration.im.tpl - looks almost like the image.illustration.im.tpl template and contains <img> tag surrounded by <li> tags. You will use this template to display thumbnail images.

Code:
<li><a href="#"><img alt="click" src="[[ src ]]" width="[[ width ]]"></a></li>


3. wrapper.illustration.im.tpl - It’s your main template, contains all of the relevant item data like title, description and includes rendered image.illustration.im.tpl and trigger.illustration.im.tpl string.

Code:
<div class="im-slider-wrapper">
    <ul class="im-slider">
        [[ images ]]
    </ul>
    <div class="val-wrapper">
        <h2>[[ title ]]</h2>
        <div>[[ description ]]</div>

        <ul class="triggers">
            [[ thumbs ]]
        </ul>
    </div>
</div>

So, let's go ahead and create the template.php file in your theme directory:

PHP Code:
<?php if(!defined('IN_GS')){ die('You cannot load this page directly.'); } ?>
<!doctype html>
<head>
    <meta charset="utf-8">
    <title>ItemManager Test</title>
    <meta name="description" content="">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="<?php get_theme_url(); ?>/css/main.css">
    <?php get_header(); ?>
</head>
<body>
<?php
// initialize our classes
$manager = new IManager();
$categoryClass $manager->getCategoryClass();
$itemClass $manager->getItemClass();

// get the Illustrations category object
$illu_cat $categoryClass->getCategory('name=Illustrations');
// init illustration items by category id
$itemClass->init($illu_cat->get('id'));

// get an active item named Medical illustrations
$item $itemClass->getItem('name=Medical illustrations && active=1');

// initialize template engine
$engine $manager->getTemplateEngine(GSTHEMESPATH.'/imtest/tpl/');
// initialize templates
$engine->init();
// get the template bundle of the illustration library
$illu_tpls $engine->getTemplates('illustration');


// get wrapper template object
$wrapper_tpl $engine->getTemplate('wrapper'$illu_tpls);
// get the image row template object
$imagerow_tpl $engine->getTemplate('image'$illu_tpls);
// get a thumbnail row template object
$thumbrow_tpl $engine->getTemplate('trigger'$illu_tpls);

// It makes image field call a bit shorter
$images $item->fields->images;

$images_wrapper '';
$thumbs_wrapper '';

require_once(
GSPLUGINPATH.'imanager/phpthumb/ThumbLib.inc.php');

// Let's loop through images and dynamically build the markup on each iteration
for($i 0$i count($images->imagename); $i++)
{
    
// render image rows
    
$images_wrapper .= $engine->render($imagerow_tpl, array(
            
'src' => $images->imagefullurl[$i],
            
'title' => $images->imagetitle[$i]
        ), 
false, array(), true
    
);

    
// create thumbnails max-width: 100px, if not done yet
    
$thumb PhpThumbFactory::create($images->imagefullurl[$i]);
    
$thumb->resize(100);
    
$ext pathinfo($images->imagefullpath[$i], PATHINFO_EXTENSION);
    
$thumb->save($images->imagepath[0].'thumbnail/100_'.$images->imagename[$i], $ext);

    
// render thumbnail image rows
    
$thumbs_wrapper .= $engine->render($thumbrow_tpl, array(
            
'src' => $images->imageurl[0].'thumbnail/100_'.$images->imagename[$i],
            
'width' => '100px'
        
), false, array(), true
    
);
}

// output
echo $engine->render($wrapper_tpl, array(
        
'images' => $images_wrapper,
        
'title' => $item->name,
        
'description' => $item->fields->description->value,
        
'thumbs' => $thumbs_wrapper
    
), true
);
?>

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
    var triggers = $('ul.triggers li');
    var images = $('ul.im-slider li');
    var target;

    triggers.first().addClass('selected');
    images.hide().first().show();

    function sliderResponse(target) {
        images.fadeOut(1000).eq(target).fadeIn(1000);
        triggers.removeClass('selected').eq(target).addClass('selected');
    }

    triggers.click(function() {
        if(!$(this).hasClass('selected')) {
            target = $(this).index();
            sliderResponse(target);
        }
    });
});
</script>
</body>
</html> 


OK, next, let us have a look at the part of the PHP code, which is really easy. During initialization, we creates instances of the model classes: Manager, Category and Item:

PHP Code:
$manager = new IManager();
$categoryClass $manager->getCategoryClass();
$itemClass $manager->getItemClass(); 


Get the Illustrations Category object and initialize all the items that belonging to this category. Below, get an active item named Medical illustrations:

PHP Code:
// get the Illustrations category object
$illu_cat $categoryClass->getCategory('name=Illustrations');
// init illustration items by category id
$itemClass->init($illu_cat->get('id'));

// get an active item named Medical illustrations
$item $itemClass->getItem('name=Medical illustrations && active=1'); 


Initialize the ItemManager’s template engine in following lines. The $manager->getTemplateEngine([path]) method expects a template path as an argument. If a path is not specified, ItemManager uses the default template path: plugins/imanager/tpl/
To get a completely template bundle of the illustration library, you can use $engine->getTemplates('illustration') method:

PHP Code:
// initialize template engine
$engine $manager->getTemplateEngine(GSTHEMESPATH.'/imtest/tpl/');
// initialize templates
$engine->init();
// get a template bundle of the illustration library
$illu_tpls $engine->getTemplates('illustration'); 


Next, get the template objects from the $illu_tpls-bundle, separated by file name:

PHP Code:
// get wrapper template object
$wrapper_tpl $engine->getTemplate('wrapper'$illu_tpls);
// get the image row template object
$imagerow_tpl $engine->getTemplate('image'$illu_tpls);
// get the thumbnail row template object
$thumbrow_tpl $engine->getTemplate('trigger'$illu_tpls); 

Loop through images and dynamically build the markup on each iteration. You can use the PhpThumb-library inside the loop to generate thumbnail images and record them in the thumbnail file with 100_ prefix, for example:

PHP Code:
for($i 0$i count($images->imagename); $i++)
{
    
// render image rows
    
$images_wrapper .= $engine->render($imagerow_tpl, array(
            
'src' => $images->imagefullurl[$i],
            
'title' => $images->imagetitle[$i]
        ), 
false, array(), true
    
);

    
// create thumbnails max-width: 100px, if not done yet
    
$thumb PhpThumbFactory::create($images->imagefullurl[$i]);
    
$thumb->resize(100);
    
$ext pathinfo($images->imagefullpath[$i], PATHINFO_EXTENSION);
    
$thumb->save($images->imagepath[0].'thumbnail/100_'.$images->imagename[$i], $ext);

    
// render thumbnail image rows
    
$thumbs_wrapper .= $engine->render($thumbrow_tpl, array(
            
'src' => $images->imageurl[0].'thumbnail/100_'.$images->imagename[$i],
            
'width' => '100px'
        
), false, array(), true
    
);



How to use $engine->render() -method:
Code:
$engine->render(object $str1[, array $tvs1 , bool $flag1 , array $tvs2 , bool $flag2 ])

The $engine->render() method expects 5 arguments:
  1. Your Template object that should be rendered.
  2. An array of placeholders and values to replace. Example: array('cms' => 'GetSimple', …) (optional)
  3. If TRUE, the function replaces the language placeholders (optional)
  4. An Array of language placeholders and values (optional)
  5. if TRUE all placeholders that doesn't have a value set, gets replaced with an empty string (optional)
The $engine->render() returns a parsed template as a string.
For example, your template $tpl could have a content like this:
Code:
<p [[ class ]]>[[ content ]]</p>
Then you could use following to parse it:
PHP Code:
$engine->render($tpl, array('class' => 'class="your-class"'
    
'content' => 'Here is your paragraph content')
); 
The output thus would be the following:
Code:
<p class="your-class">Here is your paragraph content</p>


Finally, this code compiles and renders the wrapper template for final output:
PHP Code:
// output
echo $engine->render($wrapper_tpl, array(
        
'images' => $images_wrapper,
        
'title' => $item->name,
        
'description' => $item->fields->description->value,
        
'thumbs' => $thumbs_wrapper
    
), true
); 

As you can see here, we are replacing the images and thumbs placeholders with $images_wrapper and $thumbs_wraper markup, that we would have created earlier in the For loop

Everything else is standard HTML and JavaScript you're used to seeing, from a body paragraph to a closing HTML tag.

But there's one thing: You can create a CSS file named main.css and upload it to your theme's directory. My file has the following content:
Code:
.im-slider-wrapper {
    width: 100%;
}

.im-slider-wrapper ul {
    text-decoration: none;
    list-style-type: none;
    padding: 0;
    margin: 0;
}

.im-slider {
    float: left;
    overflow: hidden;
}

.im-slider li {
    position: absolute;
}

.val-wrapper {
    float: left;
    max-width: 500px;
    margin: 0 0 0 472px
}

.val-wrapper .triggers li {
    border: solid 1px #eeeeee;
    float: left;
    margin-right: 5px;
    padding: 5px 5px 1px 5px;
    background-color: #eeeeee;
}
.val-wrapper .triggers li a {
    padding: 0;
    margin: 0;
}

.val-wrapper .triggers li.selected {
    border-color: red;
}
Reply
#27
Hi Bigin. I've been taking a look at this new version 2.1, and here is my bug report. Most of the problems I mention here were already present in the previous version; this time I've been doing more tests to try to better specify in what cases some of these errors occur. I hope you find it useful.


1 - If you double-click on a position number in the lists of categories and items, an input field appears, and you can change the position number there. But that field disappears when you click anywhere... It's Ok if it hides when you click outside the input, but not when you click inside the input, because you can't click the arrows to change the number, or select the old number with the mouse, or reposition the cursor with the mouse...


2 - The ascending or descending sort order you select in the settings for categories is not working. It's always descending. It works well with the items.


3 - The position data you see when you edit a category is not always correct. It seems it's not read from the <position> tag of the XML file. But it is correctly written... For example:
1-Create 3 categories: cat1, cat2, cat3.
2-Click on cat3 to edit. Change the position 3 to 4. Click on save.
3-Go back to the categories list. cat3 has position 4. In the XML, the tag <position> is 4. Everything is right so far.
4-Click on cat3 again. There's a 3 in the position field, instead of 4...
Position data is correctly saved from the categories editing screen, but it's not correctly read. What is shown there may be the ID...

With the items, I think it's the opposite... The position field in the item editing screen is not saved, but it's correctly read. Try this:
1-Create 3 items: item1, item2, item3.
2-Click on item3 to edit. Change the position 3 to 4. Click on save.
3-Go back to the items list. Item3 position is 3 instead of 4.
4-Double click on the Pos column in the items list and change the position. This time item3 position changes, and its value is correctly shown in the item editing screen.


4 - I think the numerical change of the position of an item should renumber the position of every item in that category, as with drag&drop. Suppose we have a category with these items:

Pos   Name
1       item1
2       item2
3       item3
4       item4

If I change the position number of Item4 to 2 in the items list screen or in the item editing screen, this should be the result:

Pos   Name
1       item1
2       item4
3       item2
4       item3

And if I change Item1 position to 13, this should be the result:

Pos   Name
1       item4
2       item2
3       item3
4       item1

If it doesn't work like that, there may be problems like this:

1-Let's say I create 60 items in a category. I want them to be in a specific order, both in back-end and front-end.
2-Later, I want to put the last item at the beginning of the list. How can I do that? I can't drag&drop because I can't see more than 50 items at a time, and if I change the last item position to 1 numerically, I'll have 2 items with position number 1. When there are multiple items with the same position number, it seems they are sorted by the file name of the XML (I'm not sure...) In any case, I can't choose which of my two items with position 1 will be first and which will be the second... Decimal numbers are not accepted as position numbers (if they were accepted I could write 1 and 1.5), so the only solution I can see for this problem is to change by hand, one by one, the position numbers of the 60 items...

Categories have the same problem with manually changed position numbers. The only unproblematic way to custom sort items or categories is to always use drag&drop, and it is not always possible.


5 - If custom fields are deleted from a category, the data is not deleted from the XML files of items, creating unnecessarily large files that will need more RAM when processed. The way to solve this is to re-save all items, one by one. I think a safe and easy solution would be to add to the settings something similar to the "Retention period for the recoverable items", to re-save all items periodically and delete the useless tags.


6 - If you create a new custom field with a name that already exists and click on "confirm", you get a message that says "The field names must be unique. The duplicates have been removed." That's fine. But if you try to rename an existing custom field and write the name of another existing custom field by mistake, it is removed without previous warning, and that's not good (there could be many items with data in that field...) I know the data is not deleted from the XML files of the items, and it will be back if you create the field again with the old name, but the end user probably won't notice that and will think all that data is lost. I think the best behavior here is to do nothing, just not to rename the custom field and show a message like "Field names must be unique. The field can't be renamed".


7 - The date picker does not work (the chosen date does not appear in the field, tested in Chrome and Firefox). The small calendar has transparent background, and it would be easier to read if it had opaque background.


8 - I think there's a small mistake in the Admin Settings text. The grey info texts about "Retention period for the recoverable items" and "Retention period for temporary image containers" are both the same. And where it says "here, you can define the minimum number of days to keep temp image data in the system directory" I guess it should say "the maximum number of days".


That's all. Keep up the good work!
Reply
#28
Thanks for this useful plugin, Bigin. Now, I’m not very proficient with PHP (I’m more of a front-end developer) – is there a simple way to sort the output by the sort order in the admin interface? Or, to say it differently: How do I sort by the “position” key in the output array?

With my limited knowledge of PHP I could probably construct a new array out of the position values and sort it, and then output it, but I suppose there is a simpler way to do it, isn’t there?

I’d be grateful for any help.
Reply
#29
Hi VIPStephan

if you select „Position“ option of Item filter in Admin, the IM automatically sorts the list according to the position attribute. You can change 'DESC' to 'ASC' if you want to reverse the order:
[Image: srt_pos_back.jpg]

To sort the results via the API you can use filterItems() - method.
Here is an example of sorting user list in descending order based on position:
PHP Code:
$manager = new IManager();

$category $manager->getCategoryClass();
$item $manager->getItemClass();

$users_cat $category->getCategory('name=Users');
$item->init($users_cat->get('id'));
$item->filterItems('position''DESC');

echo 
'<pre>';
print_r($item->items);
echo 
'</pre>'
Reply
#30
Thank you so much for your quick response, Bigin. That works perfectly. Smile
Reply
#31
Really trying to understand this plugin as it seems perfect for my project. I'm looking to output some items to a page based on criteria and for the life of me cannot figure out how to filter the items on a custom field.

This is what i have so far for my code:

Code:
<?php
    $manager = new IManager();
    $item = $manager->getItemClass();
    // Initialize all the items of category 2
   $item->init(2);
   $myitems = $item->getItems("single=1");
   print_r($myitems);
    if($myitems->items)
    {
        foreach($myitems->items as $myitems)
        {
            echo'
                <div class="row bottom-border">
                <div class="c4"><strong>' .$myitems->name . '</strong><br />' .$myitems->fields->descr->value . '</div>
                <div class="c2 text-center">$' .$myitems->fields->small->value . '</div>
                <div class="c2 text-center">$' .$myitems->fields->medium->value . '</div>
                <div class="c2 text-center">$' .$myitems->fields->large->value . '</div>
                <div class="c2 text-center">$' .$myitems->fields->xlarge->value . '</div>
                </div>
            ';
        };
    };
?>
When i print i can see the array with my items in them but i can not get an output from that array. I know i'm just missing something silly as it works with i just init the category.


Some insight would be great on how i can use a filtered list of items.
Keeping it simple means making progress!!
Reply
#32
Hi xrmarcis,

Try following:

PHP Code:
$manager = new IManager();
$item $manager->getItemClass();
// Initialize all the items of category 2
$item->init(2);
// To get your items on single field
$items $item->getItems("single=1");

if(
$items)
{
    foreach(
$items as $myitems)
    {
        echo 
'
                <div class="row bottom-border">
                <div class="c4"><strong>' 
.$myitems->name '</strong><br />' .$myitems->fields->descr->value '</div>
                <div class="c2 text-center">$' 
.$myitems->fields->small->value '</div>
                <div class="c2 text-center">$' 
.$myitems->fields->medium->value '</div>
                <div class="c2 text-center">$' 
.$myitems->fields->large->value '</div>
                <div class="c2 text-center">$' 
.$myitems->fields->xlarge->value '</div>
                </div>
        '
;
    };
}; 

That should do the trick.

if you use $item->getItems() method, in case it's important that you use just $myitems, not $myitems->items. Because $item->getItems() returns an array of the item objects
Reply
#33
(2016-01-31, 17:23:56)Bigin Wrote: Hi xrmarcis,

Try following:



PHP Code:
$manager = new IManager();
$item $manager->getItemClass();
// Initialize all the items of category 2
$item->init(2);
// To get your items on single field
$items $item->getItems("single=1");

if(
$items)
{
    foreach(
$items as $myitems)
    {
        echo 
'
                <div class="row bottom-border">
                <div class="c4"><strong>' 
.$myitems->name '</strong><br />' .$myitems->fields->descr->value '</div>
                <div class="c2 text-center">$' 
.$myitems->fields->small->value '</div>
                <div class="c2 text-center">$' 
.$myitems->fields->medium->value '</div>
                <div class="c2 text-center">$' 
.$myitems->fields->large->value '</div>
                <div class="c2 text-center">$' 
.$myitems->fields->xlarge->value '</div>
                </div>
        '
;
    };
}; 

That should do the trick.

if you use $item->getItems() method, in case it's important that you use just $myitems, not $myitems->items. Because $item->getItems() returns an array of the item objects

That worked perfect i have an issue though with the not operator. I've tried != and <> but it does not seem to work. single is a checkbox field. Any suggestions?
PHP Code:
<?php
    $manager 
= new IManager();
    
$catItems $manager->getItemClass();
    
// Initialize all the items of category 2 
 
   $catItems->init(2);
 
   $filteredCatItems $catItems->getItems("single<>1");
    if(
$filteredCatItems)
    {
        foreach(
$filteredCatItems as $menuItem)
        {
            echo
'
                <div class="row bottom-border">
                <div class="c4"><strong>' 
.$menuItem->name '</strong><br />' .$menuItem->fields->descr->value '</div>
                <div class="c2 text-center">$' 
.$menuItem->fields->small->value '</div>
                <div class="c2 text-center">$' 
.$menuItem->fields->medium->value '</div>
                <div class="c2 text-center">$' 
.$menuItem->fields->large->value '</div>
                <div class="c2 text-center">$' 
.$menuItem->fields->xlarge->value '</div>
                </div>
            '
;
        };
    };
?>
Keeping it simple means making progress!!
Reply
#34
If you want to get unchecked values then you can use name!=1 selector:

PHP Code:
$filteredCatItems $catItems->getItems("single!=1"); 

or

PHP Code:
$filteredCatItems $catItems->getItems("single="); 

both is correct.
Reply
#35
(2016-02-01, 00:41:29)Bigin Wrote: If you want to get unchecked values then you can use name!=1 selector:


PHP Code:
$filteredCatItems $catItems->getItems("single!=1"); 

or


PHP Code:
$filteredCatItems $catItems->getItems("single="); 

both is correct.

lol I thought i tried that but yes that worked for me. Thank you
Keeping it simple means making progress!!
Reply
#36
Another quick question about money fields. My field values seem to be getting the zeros trimmed for some reason.

I setup 4 money fields and keyed the retail in each one and this is what i get.

Small - 0.99 displays as 0.99
Medium - 3.00 displays as 3
Large - 4.50 displays as 4.5
Extra Large - 6.57 displays as 6.57

Code:
            echo'
                <div class="row bottom-border">
                <div class="c4"><strong>' .$menuItem->name . '</strong><br />' .$menuItem->fields->descr->value . '</div>
                <div class="c2 text-center">$' .$menuItem->fields->small->value . '</div>
                <div class="c2 text-center">$' .$menuItem->fields->medium->value . '</div>
                <div class="c2 text-center">$' .$menuItem->fields->large->value . '</div>
                <div class="c2 text-center">$' .$menuItem->fields->xlarge->value . '</div>
                </div>
            ';


I know this has something to do with the format but i thought if i used the money field it would know that currency is #,###.##.

Is there other formatting i need to do after the data is pulled in order to get the full value?

I've checked the notation and they are all set to English.

Once again thank you for your support.
Keeping it simple means making progress!!
Reply
#37
Feature request:

Bulk update tool - Used to update all records in a category when category fields have been added after there have been items created in the category.

I recently ran into this today while creating filters and could not understand by my items were not filtering properly. I figured out when i went back into a previously created item and just updated it. Its started appearing in my filtered item list.

Thank you for the great plugin.
Keeping it simple means making progress!!
Reply
#38
The money field format means that only apply to the input in admin, the value stored in the field is always a float type. IM does not care about the output and always gives values in the raw format.

You have to use a PHP standard function like money_format() to format a number value as a currency string country/region specific.

US national format for example:
PHP Code:
setlocale(LC_MONETARY'en_US');
money_format('%!n'$menuItem->fields->small->value
Reply
#39
(2016-02-01, 01:59:42)xrmarcis Wrote: Feature request:

Bulk update tool - Used to update all records in a category when category fields have been added after there have been items created in the category.

I recently ran into this today while creating filters and could not understand by my items were not filtering properly. I figured out when i went back into a previously created item and just updated it. Its started appearing in my filtered item list.

Thank you for the great plugin.

You can add as many additional fields as you like, even after there have been items created in the category.

I do not think that it’s a good idea to allow IM to modify field values of all items that’s being stored, on every time a new category field is created.
And of course you can already do it very simple by using ItemManager API.
For example, to set all the values of your „single“ checkbox to checked, you can use following code:

PHP Code:
$manager = new IManager();
$catItems $manager->getItemClass();
$catItems->init(2);
if(
$catItems->items)
{
    foreach(
$catItems->items as $item)
    {
        if(
$item->setFieldValue('single'1))
        {
            
$item->save();
        }
    };
}; 

That it’s your Bulk update tool lol
Is not it easy? Now try the same with an ugly array ;-)
Reply
#40
ItemManager 2.2 is released

New Features:
  1. MarkupSectionCache Usage example
  2. CategoryJoins Usage example
Reply
#41
Hi!

I created some categories and items (for examples, slugs for categories and items: one, two, three ...)
Is it possible automatically get lists of categories and items (with my fields) on the site???

I can't understand this instructions http://ehret-studio.com/lab/2015/mai/itemmanager-2.0 and where paste php code. I'm dumb in this.
Reply
#42
Hello,

(2016-03-06, 11:11:08)samdecks Wrote: I can't understand this instructions http://ehret-studio.com/lab/2015/mai/itemmanager-2.0 and where paste php code. I'm dumb in this.

No problem you will succeed


(2016-03-06, 11:11:08)samdecks Wrote: I created some categories and items (for examples, slugs for categories and items: one, two, three ...)

I don't understand, are this the slugs of categories or item names or both, or you have created a slug-field for items?

(2016-03-06, 11:11:08)samdecks Wrote: Is it possible automatically get lists of categories and items (with my fields) on the site???

Again, I can’t understand this, what exactly you would like to list, categories or items or both?

I think, if you have decided on using ItemManager in your project, first off, you must develop a real scheme and to ask to yourself: what exactly I wanted to do?
ItemManager gives you full control of all your output, you have 100% freedom with markup and content structure, but ItemManager can't do magic, you will have an idea for starting a new project and you need to be little creative.
Reply
#43
(2016-03-06, 11:11:08)samdecks Wrote: I created some categories and items (for examples, slugs for categories and items: one, two, three ...)
Is it possible automatically get lists of categories and items (with my fields) on the site???

A small tutorial how to create a simple category list:
http://ehret-studio.com/lab/2015/mai/tut...emmanager/
Reply
#44
I placed my website in the folder and no image http://getsimple-themes.ru/im/catalog/
codes took here http://ehret-studio.com/lab/2015/mai/tut...emmanager/
Reply
#45
Ahhh, yes, it’s a known bug, I completely forgot about it: https://github.com/bigin/ItemManager_2.0/issues/1

Now I've fixed it, a big thx Oleg!
ItemManager v. 2.3.1 in Extend

Upgrade:
  • Replace file: /plugins/imanager.php with the new version
  • Replace directory: /plugins/imanager with the new version

  • After making changes, you will need to re-save all your items with an image field from admin manually.
Reply
#46
where I can set up pagination?
Reply
#47
Hmm… ItemManager can paginate some things: items, categories and fields. There are tons of ways to render navigation for pagination with ItemManager:
The easiest way would be to use the pagination with default ItemManager’s templates. These are typically just fine, but there may be an instance where you want to modify the markup and behavior. If required so, you can completely customize your pagination, by implementing your own markup and CSS.

But today I'd like to share with non-programmers a function that you can use in your web projects to paginate your items and categories:

PHP Code:
function paginate(& $im, & $ia$max 20)
{
    
$tpls = array();
    
$tpl $im->getTemplateEngine();
    
$tpl->init();

    
$pagination $tpl->getTemplates('pagination');
    if(empty(
$pagination)) return false;

    
$prevTpl $im->newTemplate();
    
$prevTpl_inactive $im->newTemplate();
    
$nextTpl $im->newTemplate();
    
$nextTpl_inactive $im->newTemplate();
    
$prevTpl->content '<a class="paginator-left" href="[[href]]">prev</a>';
    
$prevTpl_inactive->content '<span class="paginator-left">prev</span>';
    
$nextTpl->content '<a class="paginator-left" href="[[href]]">next</a>';
    
$nextTpl_inactive->content '<span class="paginator-left">next</span>';

    
$tpls['wrapper'] = $tpl->getTemplate('wrapper'$pagination);
    
$tpls['prev'] = $prevTpl;
    
$tpls['prev_inactive'] = $prevTpl_inactive;
    
$tpls['central'] = $tpl->getTemplate('central'$pagination);
    
$tpls['central_inactive'] = $tpl->getTemplate('central_inactive'$pagination);
    
$tpls['next'] = $nextTpl;
    
$tpls['next_inactive'] = $nextTpl_inactive;
    
$tpls['ellipsis'] = $tpl->getTemplate('ellipsis'$pagination);
    
$tpls['secondlast'] = $tpl->getTemplate('secondlast'$pagination);
    
$tpls['second'] = $tpl->getTemplate('second'$pagination);
    
$tpls['last'] = $tpl->getTemplate('last'$pagination);
    
$tpls['first'] = $tpl->getTemplate('first'$pagination);

    
$params['page'] =  !empty($_GET['page']) ? (int) $_GET['page'] : 1;
    
$params['items'] = count($ia->items);
    
// start item
    
$start = (($params['page']-1) * $max+1);
    
// order items
    
$ia->filterItems('position''DESC'$start$max);
    
$params['lastpage'] = ceil($params['items'] / $max);
    
$params['limit'] = $max;
    
$params['pageurl'] = '?page=';

    return 
$im->buildPagination($tpls$params);


You can paste this paginate()  function in your functions.php file.
This function could be called right after you are calling: $itemsAccessor->init() or $categoryAccessor->init() functions. For example, your functions.php code in this tutorial could then look something like this:

PHP Code:
<?php
// get the current page slug
$slug get_page_slug(false);
// Check whether the slug is 'catalog'
if($slug == 'catalog') {
 
   // initialize ItemManager
 
   $imanager = new IManager();
 
   // let's get our DUMMY's category, we only need the ID-number of the category
 
   $catAccessor $imanager->getCategoryClass();
 
   $categoryData $catAccessor->getCategory('name=Category Data');
 
   if(empty($categoryData)) die('Category Data was not found');
 
   // get the items of DUMMY category
 
   $itemsAccessor $imanager->getItemClass();
 
   $itemsAccessor->init($categoryData->get('id'));
 
   ///////// YOUR paginate() CALL COMING HERE ////////////
 
   $pagination paginate($imanager$itemsAccessor1);
 
   if(empty($itemsAccessor->items)) die('Categories not found');
 
   // Done! We can now use our categories with $itemsAccessor->items in our template.php



After that, you can call echo in your template.php file in order to output the value returned by the paginate() function:

PHP Code:
<?php if($slug == 'catalog') { ?>
    <h1>MY PRETTY CATALOG</h1>
    <p>Select a category</p>
    <?php foreach($itemsAccessor->items as $category) { ?>
        <article>
            <h2><a href="./<?php echo $category->fields->slug->value?>/"><?php echo $category->name ?></a></h2>
            <div>
                <p><img alt="<?php echo $category->fields->image->imagetitle[0?>"
                        src="<?php echo $category->fields->image->imagefullurl[0?>"></p>
                <div class="category_text"><?php echo $category->fields->description->value?>
                    <a href="./<?php echo $category->fields->slug->value?>/">Shopping</a>
                </div>
            </div>
        </article>
    <?php 
      
}
      
//////////// OUTPUT YOUR PAGINATION /////////////
 
     echo (!empty($pagination) ? $pagination '');
}
?>


Code:
paginate( object $imanager, object $itemAccessor, int $max )
Parameters:
  • $imanager = is an instanze of IManager class
  • $itemAccessor = is an instance of item- or category-accessor
  • $max = the maximum number of items per page

Return Value:
  • A markup output for your pagination
Reply
#48
File repository by ItemManager

It’s best to download the latest version (2.3.2 +) of IM from extend http://get-simple.info/extend/plugin/itemmanager/936/, so you can create a new field "File upload" this allows you to upload any file formats you like.

Then, you create a new category named "repository" for example and create a field of "File upload" type for that, named "files".
Go to "Fields" menu and click "Edit field" (the gear icon), scroll down the page to "Enter accepted file types" area and specify the files types there by entering file extensions separated by pipe "|" that you want to allow to upload. For images and PDF-files you can enter following: gif|jpe?g|png|pdf

After you can create any items you like, upload your files and type any title for that.

[Image: file_upload_field.png?dl=1]

After that design any markup you like to display the files at the frontend. You can use the code like follows in your template (PHP5.4 +):


PHP Code:
<?php
$im 
= new IManager();
$itemSelector $im->getItemClass();

/* Change "11" with your repository category-ID */
$itemSelector->init(11);
$active $itemSelector->getItems('active=1');
foreach(
$active as $item)
{
if(empty(
$item->fields->files)) continue;

echo 
'<fieldset>';
echo 
' <legend>'.$item->name.'</legend>';
echo 
' <div>';
foreach(
$item->fields->files->file_name as $key => $filename) {
if(empty(
$filename)) continue;
$url = !empty((string)$item->fields->files->fullurl[$key]) ? $item->fields->files->fullurl[$key] : '';
$description = !empty((string)$item->fields->files->title[$key]) ? $item->fields->files->title[$key] : '';
// Render output
echo '<p><a href="'.$SITEURL.$url.'" >'.$description.'</a></p>';
}
echo 
' </div>';
echo 
'</fieldset>';
}
?>

Demo: http://im.ehret-studio.com/file-listing/

BTW: If you want to go a step further you can even use Frontainer http://get-simple.info/extend/plugin/frontainer/1015/ to set custom permissions for any created downloads.
Reply
#49
Hello. Can you, please, show me where to read about how to get to the detailed page of item?
Right now I've managed to render the list of all my item from a category. How can I create a template for my Item page so I can have a structure like this:

Home -> Category page -> Item page
 
Thank you in advance.
Reply
#50
Hi, do you want to show an item list of a category or details page of a single item?

Can you show me a piece of your code for rendering the item list?
Reply




Users browsing this thread: 1 Guest(s)
Free HDTV Channels Residential Solar Panels