gteigland VIP
Total posts: 159
27 Jun 2015 02:39

I totally understand that this is elementary for you and Ive read both thoroughly your template customization but just need a few things filled in and I can figure out the rest.

Basically all Im trying to do is get my featured image field to show above the title in records listing view. http://www.awesomescreenshot.com/image/361660/a0aaac854593cd22a62051bf46e42a34

  1. When I put code in my new template like this:
  <div class="featuredimg">             
        <?php
if(isset($item->fields_by_id[9])): ?>
       <?php echo $item->fields_by_id[9]->result; ?>
<?php endif; ?> 
</div> 

(This is for featured img) -- I get this: http://www.awesomescreenshot.com/image/361662/4a12aab095855d03c27d72137bcd3058

I get two images. (one from my hard code and the other from selecting Yes to Intro View) I figured a workaround would be deselected "intro view" in my field settings (since I assumed I hard coded this) but it removed both of my images.

LIke I said I read the documentation on template customization but can't quite figure out how to do this.

A little help would get me on my way for other stuff I need to do.

Thanks!

Last Modified: 25 Jul 2016


pepperstreet VIP
Total posts: 3,837
27 Jun 2015 13:13

Hello gteigland, most likely this is a result of using the automatic "default field loop" in combination with your custom lines to call a single field. You can find the answer and code in the following docs article:

Scroll down to the bottom, hence the last Question:

Q: What if I display explicitly only one field and rest I want to fetch and I do not want this field to be listed in the cycle?

See the code example and the line with UNSET function/command. This will remove the default field form the usual output-loop.


gteigland VIP
Total posts: 159
27 Jun 2015 14:04

Thanks for the response. I guess that is where I have been confused (as I've read these articles more the once) as it relates to added fields into the params.

This code you give as an example:

<?php if(isset($item->fields_by_key[$params->get('tmpl_params.field_price')])):?>
    <span class="price-tag">
          <?php echo $item->fields_by_key[$params->get('tmpl_params.field_price')]->result; ?>
          <?php unset($item->fields_by_key[$params->get('tmpl_params.field_price')]);?>
    </span>
<?php endif; ?>

My confusing lies in how you do you get the field name field_price. I see that the fields have ids but I don't see for example an alias for that field so I know what name to put in there.

For example with this code you provide above i see field_price. So if I have a field name of Featured Image... what do I put in there? I doubt it would be a label name as you could have more then one field with the same label.

I realize I'm not thinking clearly and am missing something basic (as I'm new) but I just can't figure out how I call a specific field in this example as opposed to using the id or key.

Thanks for your help!


gteigland VIP
Total posts: 159
27 Jun 2015 14:10

One more thought. I understand your documentation of added the field to the parameters as documented here.

<fields name="tmpl_params">
     <fieldset name="name1" label="Position Fields" 
         description="Set fields to be positioned">
         <field name="field_price" type="meresourcesfields" label="Where is the price?" />
     </fieldset>
 </fields>

What Im not getting is that you put in the field name "field_price" Where in the backend do we get the name for our field. Because like I said it can't be the label name as that could be the same for multiple. So if I have a field Featured Image what am I replacing "field_price" with. Also confused on the "meresourcesfields" involving type

Again I know basic for you but I just need some clarity so I can undestand this better.

Thanks!


pepperstreet VIP
Total posts: 3,837
27 Jun 2015 15:37

Sorry, my doc reference is indeed confusing! Did not notice the relation to the specific usage with field parameter. This is a special case and usage. The docs should be reviewed and there have to be an example "without" the template parameter stuff, IMHO. ;)

So, the current example does apply if you want to select a field in your template parameters... after saving the template it will show and unset your selected field.


If you don`t have/need a field selection in template, you can use the other methods to get a field: Either by ID, or KEY. This is explained in the same docs article, in upper area.
If you have only 1 type, you can use ID method. KEY method is suggested for multi-type sections.


pepperstreet VIP
Total posts: 3,837
27 Jun 2015 15:54

In your first example you can add the unset right AFTER the echo:

<?php unset $item->fields_by_id[9]; ?>

Example with slightly different HTML markup...

<?php if(isset($item->fields_by_id[9])): ?>
    <span class="field-image featured yourclass">
        <?php 
            echo $item->fields_by_id[9]->result; 
            unset $item->fields_by_id[9]; 
         ?>
    </span>
<?php endif; ?>

gteigland VIP
Total posts: 159
28 Jun 2015 01:04

THANKS! Much clearer and I was able to accomplish what I needed!


gteigland VIP
Total posts: 159
06 Jul 2016 20:15

For some reason this unset code is not working anymore and looking at the documentation I dont see any changes. I've added this code for field ID 11 as Im calling it outside the typical order but then need to unset it so i doesn't double up on the page:

<?php if(isset($item->fields_by_id[11])): ?> <?php echo $item->fields_by_id[11]->result; ?> <?php unset($item->fields_by_id[11]);?> <?php endif; ?>

Howeve when you look at this page you will see two image galleries showing and the unset it not working. Am I missing something here?

http://dev.mckcamera.com/index.php?option=com_cobalt& ;view=record&id=29:mck-235code&Itemid=127


gteigland VIP
Total posts: 159
08 Jul 2016 02:24

pepperstreet VIP
Total posts: 3,837
08 Jul 2016 22:37

I guess, you are right. The () are not the issue... my fault.
I could not get it to work either. Apparently something might have changed!?

Please, wait for official answer...


gteigland VIP
Total posts: 159
10 Jul 2016 13:57

Here is some additional info. Background 1. Try to edit the records listing 2. Adding this code <?php if(isset($item->fields_by_id[11])): ?> <?php echo $item->fields_by_id[11]->result; ?> <?php unset($item->fields_by_id[11]);?> 3. ON the page I got this error. Notice: Undefined offset: 42 in /var/www/vhosts/mckcamera.com/dev.mckcamera.com/components/com_cobalt/views/records/tmpl/default_list_mck-camera-list.php on line 208 4. The code that is refernce is this from line 208 $exclude = $params->get('tmpl_params.field_id_exclude'); settype($exclude, 'array'); foreach ($exclude as &$value) { $value = $this->fields_keys_by_id[$value];

See attached screenshot http://www.awesomescreenshot.com/image/1384797/57560f52c6bad4024a5d532254a8590b

Here is the live link: http://dev.mckcamera.com/index.php?option=com_cobalt& ;view=records&section_id=2:cameras&Itemid=127


pepperstreet VIP
Total posts: 3,837
11 Jul 2016 12:45

Still no clue about the full record view, sorry.

gteigland 1. Try to edit the records listing

In the list template parameters you should have a parameter to exclude fields. Did you try this?

You don't have to code an UNSET manually. Stating the obvious, but also make sure your fields are set to show up in intro/full view. Otherwise they are not available. This might lead to "Notices" as well.

Bildschirmfoto 2016-07-11 um 15.01.52


gteigland VIP
Total posts: 159
11 Jul 2016 12:52

Yes I do know that but what I'm trying to change the order of the image compared to title. For example I want the image BEFORE the title of the record. So this is what i did before on another site So I code it in with fields by id. The last time i did this it would create a double field of that id so I had to unset the default. It's basicaly about changing layout and for some reason because the unset and even fields by id is not working I'm not able to do that.


pepperstreet VIP
Total posts: 3,837
11 Jul 2016 13:00

gteigland and even fields by id is not working I'm not able to do that.

You mean, you can't even get a field by ID and display it?


The output should work fine with field ID:
Make sure to echo it before the default loop.
Make sure the field is available in respective view context. (Intro/Full)
Bildschirmfoto 2016-07-11 um 16.32.12


gteigland VIP
Total posts: 159
11 Jul 2016 17:06

Thats not that issue. that works fine.

I'm referencing the code above that you acknowledget doesn't work anymore and referenced in the cobalt docs. Correct i can't get an field by id to show in items listing. Yes it will show when I have it set to yes for intro view HOWEVER.. that not the code by id but just puttin it to yes on listing in backend. if i can it in again manually it should show twice and then I have to unset one of them again -- the reason i need to this is so I can customie the template and call in the fields and place them in the order i want instead of whats its ordered in backend. Also the error message won't go away no matter what I do.

Notice: Undefined offset: 42 in /var/www/vhosts/mckcamera.com/dev.mckcamera.com/components/com_cobalt/views/records/tmpl/default_list_mck-camera-list.php on line 208

Thanks


pepperstreet VIP
Total posts: 3,837
11 Jul 2016 23:29

gteigland HOWEVER.. that not the code by id but just puttin it to yes on listing in backend.

In default list- and full- template, I am able to show a field by ID. Also by KEY. It shows up twice.
I have issues with UNSET in full-view only.


Did you try the current/latest default templates? Just for comparison.
Would you mind to attach your templates as a ZIP file?


gteigland VIP
Total posts: 159
12 Jul 2016 02:03

I cant get any field id to work in listing view in fact i have other issues with listing template as referenced in this new ticket I put together. http://www.mintjoomla.com/support/community-forum/user-item/4463-gteigland/48-cobalt-8/6800-not-able-to-edit-template-listing.html


gteigland VIP
Total posts: 159
13 Jul 2016 21:13

pepperstreet I guess, you are right. The () are not the issue... my fault.

I could not get it to work either. Apparently something might have changed!?

Please, wait for official answer...

Any word on this?


Sergey
Total posts: 13,748
24 Jul 2016 05:30

gteigland

pepperstreet I guess, you are right. The () are not the issue... my fault.

I could not get it to work either. Apparently something might have changed!?

Please, wait for official answer...

Any word on this?

I thought we solved it in the other topic. So what is your question again? I kinda lost in all your same subject topics.


gteigland VIP
Total posts: 159
25 Jul 2016 20:48

It's ok lets just move on -- I figured out a work around -- my real issue is the module filter records I've mentioned in other topic.

Powered by Cobalt