1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

V4.1.x Displaying variables and extra fields NOT already shown on the page

Discussion in 'Modules / Plugins / Modifications' started by seymourjames, Jul 4, 2009.

  1. seymourjames All Hands On Deck

    The question of can I display extrafields or certain variables on page where they are not present by default, is a question which comes up, time after time.

    The forum is full of answers which could be found by searching for them. Hence this sticky because it may provide a quick answer near the top and the question will not need to be asked.

    First of all there is a function in the plugins directory called function.get_extra_field.php. It is used very simply as follows in your template files:

    {get_extra_field id=2 fid=1}

    where id is the advert listing id and fid is the identification number of the extrafield which is show in your admin control panel. Now if the listing id is needed as a variable, instead of the number 2 then you will need to put in that variable. For example if you wish to display the extrafield with fid=2 in your showlistings for every listing you will have this within the loop displaying the lsitings:

    {get_extra_field id=$entry.id fid=2}


    $entry.id is the variable for identifying each listing.

    Now which variables are available in general on a page. This is simply a matter of putting {debug} temporarily into the top of the layout.tpl file.

    As you browse through the pages on your site, a popup will show you exactly which variables are available on that page. If the variable is not present then the only option is to engage in core file changes which may be complex (not something which is generally recommended as it makes upgrades much more difficult) or write a module to get that specific variable.
  2. vertyal Customer

    Thanks, I put the {debug} in, and I found something real strange. As expected, I do not see $lastname and $firstname as assigned variables, which explains why the code does not work for the full name. However, I do not see $username as assigned variable either, which makes me think why I still can use the $entry.username variable on the very same page.
  3. vertyal Customer

    Sorry, I found $username under the $results variable....
    Thanks for your help.:)
  4. metrony Customer

    Is there anyway to strip out the pipe character in the results? For example purposes let's say the result from {get_extra_field id=$entry.id fid=2} = "Red". It shows up as "Red|" since fid=2 is a checkbox field.
  5. seymourjames All Hands On Deck

    Look in the php manual on how to strip character and apply it within the plugin.
  6. TemplateCodes-Mike TemplateCodes

    I ran into this issue before as well on a project for a client. What I did was to make a copy of this plugin and renamed it. Although there were many other things that I was trying to achieve with the final output, I came across the exact issue that you are referring to.

    In this particular case, I wanted to get rid of the pipes ("|") and replace them with commas (",") and in addition, for some reason the output also always gave one additional result which was blank, yet had a pipe at the end.

    Here's what I did, to solve that issue around line 74: (This should get you in the right direction to customize it to your tastes)
    PHP:
    if($result->size()>0)
        {
            
    $rs=$result->fetch();
            
    $rs['sValue']=str_replace(" | "", "$rs['sValue']); //replace the pipe with a comma
            
    $rs['sValue']=str_replace("|"""$rs['sValue']); //get rid of the last extra pipe
            
    $info $rs['sValue'];
        }
  7. TemplateCodes-Mike TemplateCodes

    Just to elaborate on what David posted, because this comes up all of the time in trying to use the {debug} functionality of Smarty. A few things to bear in mind to do this correctly.
    1) You add the {debug} to the very top of the layout.tpl file in your current template folder
    HTML:
    {debug}
    {*$Revision: 441 $*}
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    You then save the file and upload it to your server. In order for the pop-up window to appear, you MUST TURN OFF ANY POP-UP WINDOW BLOCKER YOU HAVE ENABLED! In addition, if you are using the SEO Friendly URLS module YOU MUST DEACTIVATE THAT MODULE!

    2) You must go to the actual page that you are trying to discover the variables for. In other words if you are trying to see what is available after you search, you must then conduct a search. (although it may be annoying, the pop-up window will pop-up for each page that you visit)
    Tip: If you use a browser such as Safari where pop-up window blocking is a menu item, you can keep pop-up menu blocking turned off until you get to the page you want the variables for, then turn it on for that page to avoid all of the extra pop-up windows.

    3) The variables assigned to a template page WILL AND DO VARY FOR DIFFERENT TEMPLATES PAGES!

    4) The Smarty {debug} functionality IS NOT the same thing as the "Debug" module. The "Debug" module is mainly a developers tool that shows all queries to the database for the page that you are visiting. Good for debugging php code such as when you are developing a module for example.
  8. metrony Customer

    And if you just want to remove the pipe you can use the following code (removes the last character)

    {get_extra_field|substr:0:-1 id=$entry.id fid=2}

    Just an fyi that smarty code syntax is different than php syntax so for other examples you'll have to look up what it is exactly.
  9. KLOUGOON Customer

    Hi I am new to this software and web prgramming in general but am familiar with database development. I have managed to get the extra fields I want showing however I want to add some customisation.

    Not all catagories contain the extra fields I have setup to show in the showlistings template which is fine. If they don't exist they don't show up - all good so far.

    However when they do show up they show only the value of the field. As with some of the items listed it is not easy to differentiate whether each one is the make, model or whatever I want to be able to say essentially that if the field exists in the listing show "Make:" then extra field value. I have tried an If statement but no matter which way I structure it it always evaluates to the "else" part of the statement.

    I am sure it is something simple and I have trawled through the forum trying to find the answer but all replies seem to be just the extra field value itself. If there is someone who could point me to an existing thread that would be great or sould someone have a look at what I have been trying and provide some guidance.

    I am using v4.1.10 Developer with the Sigma templates

    Here is the if statement I had tried:
    Code:
    {capture name='condition'}
     {get_extra_field id=$entry.id fid=4}
     {/capture}
     {if $smarty.capture.condition==""}
     <td{if $entry.class<>""} class="{$entry.class}"{/if}>Condition: {get_extra_field id=$entry.id fid=4}</td>	
     {else}
     <td{if $entry.class<>""} class="{$entry.class}"{/if}>{get_extra_field id=$entry.id fid=4}</td>
     {/if}
  10. T0m1 Customer

    Hi there,

    I am no whizz kid, and I am just starting out myself. But If I was to have a good guess as to why its defaulting to the else statement id say it was because of this line in your code
    Code:
    {if $smarty.capture.condition==""}
    
    From what I understand that statement is sayingif, the smarty capture'condition' is equal to nothing

    Ok im out of my depths here, but try this one
    Code:
     {if not $smarty.capture.condition==""}
    
    And hopefully if im not mistaken it should then perform this

    if, the smarty capture 'condition', is NOT equal to nothing

    Kind regards,
  11. KLOUGOON Customer

    Thanks for the quick reply. Have tried that and still no luck. It comes up with the text Condition: even when the extra field does not exist. I had tried a few other variations of this statement all with the same result. All listings either come up with the prefix or they don't - I just can't seem to get the validation right.
  12. seymourjames All Hands On Deck

    Why not follow through on Mike's post - make a copy of the plugin and do the testing/output inside the smarty plugin. I think you will have more luck this way.
  13. business Customer

  14. Mike-N-Tosh Owner

    Yes, this was also why I created a copy of this plugin. One of the other issues was that I wanted to only show a fields value if there was one AS WELL AS the field name. The issue is, that the plugin only gets the value. The actual field name isn't even stored in the same database table. So here's how you can do this.

    1. Make a copy of the plugin and name it: function.get_extra_field2.php

    2. Around line 31 (the beginning of the function)
    change this: function smarty_function_get_extra_field($params, &$smarty)
    to this: function smarty_function_get_extra_field2($params, &$smarty)
    (this is so the file name and the function match or it won't work)

    3. Around line 47 after the two separate "}" and "}" for the foreach satatement add this new code to get the extra fields name. This will get the field name that we need.
    PHP:
    if($fid >0)
    {
        
    $sSQL "SELECT fName FROM ".PREFIX."fields WHERE fID='".$fid."'";
        
    $result=$db->query($sSQL);
        if(
    $result->isError())
        {
            return 
    false;
        }
        if(
    $result->size()>0)
        {
            
    $rs=$result->fetch();
            
    $ftitle $rs['fName'];
        }
    }
    4. Around line #76 (originally line #62) find: return $value; DELETE THIS LINE!

    5. Just before the very last "}" insert this new code:
    PHP:
    If($value<>"")
    {
        
    $output $ftitle':&nbsp;' .$value//insert whatever design html output you want here
    } else {
        
    $output '';
    }
    return 
    $output;
    The last step (5) is where you can alter this to match your design if you want to
    example:
    $output = '<tr><td class="field_name">' .$ftitle. '</td><td class="field_value">' . $value. '</td></tr>';

    Now you can use this plugin the same way except that you would use the proper name:
    Example {get_extra_field2 id=2 fid=1}
  15. T0m1 Customer

    Mike, just a quick Question which may or may not be related to this topic (hence no new thread).

    When creating extra fields is it possible to place certain ones specifically within viewlisting.tpl and the rest automatically be bunched together (so say another new one was created this was auto output without needing to again modify the tpl file).

    But likewise to arrange these in a specific order int he form a user fills out and then any I do not manually place are auto output together (like they currently are)?

    Many thanks and sorry if its not relevant to this thread.
  16. Mike-N-Tosh Owner

    Short answer: NO

    It's all or nothing, basically. The extra fields are gathered and displayed with the ajax file. However as far as ordering the display of ALL of the extra fields in the viewlisting as well as the checkout and advanced search, it is ordered by the field order as set in the extra fields list in the admin.
  17. T0m1 Customer

    Hmm,

    Not really what I was hoping for lolol.

    Which means I am a little stuck now as it would be completely bizarr to have the price near the top (when listing a new item) then have a bunch of other fields then select ONO,OVNO etc, and then whether it is for Swap, Sell etc .

    Likewise in the output on the front end it would completely daft...

    I would have loved to modify viewlisting.tpl so that seller details were on the right, "Sell,Swap" appears at top with price underneath and ONO,OVNO next to it and then a little bit of a break (as the price would be formatted differently) and then the other extra fields along with the description box.

    Actually just bumped into this post... http://www.68classifieds.com/forums...fication-display-extra-fields-separately.html ...

    Would this work? If yes, how would I go about giving more than 1, 2 or maybe even 3 extra fields their own name to display seperately?

    Many thanks.
  18. Mike-N-Tosh Owner

    No. That is for v4.0.x
  19. seymourjames All Hands On Deck

    The post is dated 02-28-2008 . It is for a very old version of 68C. I doubt it will do what you hope for but you can try. Experimenting is important.

    Why do you not set up your extrafields to not display in a listing. Then use the extrafield plugin in the locations you wish to display the extrafields? Its potentially going to be be tedious and a bit messy but you are choosing to do something out of the ordinary. Managing extrafields on checkout and search are a different matter. There is a solution for search which is to remove the ajax stuff from search.tpl and hardcode in the labels and options in the order you wish them to display. That is exactly what we did on this site Annunci Immobiliari when we put search on the home page. The solution for search is only going to work though if your extra fields remain the same for all categories (the category structure is also flat - no subcats) and the extrafields are permanently shown on the search. Not sure how you would go about doing the checkout process at all. I think that will require a hell of a lot of customization. I would not even consider that.

    To be frank again Tom. You are focussing on widgetry. Not much of this is going to make a difference to the success of your site. Looking at your overall goal as it is becoming clearer you need to find a top notch developer who can really dig into the internals of the code to make the types of modifications you would like to the system of extrafields. You are pressing 68C beyond the limits it was designed for if you want to accommodate sales, swaps, etc. As in the example site above you may be able to use our global search module to manage the fields in search and the listing filter to differentiate sales and swaps (in our case sales and renting) but it is not going to get you all of the way.

    As Larry previously mentioned. Some of the most simple sites are by far the most successful.
  20. T0m1 Customer

    Hi Mike & David,

    Many thanks to both of you for taking the time to respond and help in my enquiry :) .

    @David
    Its not that I want to make the site complex, not by any means, and at present im not interested in any automated selling/swapping thing.

    I just (and for me personally I would see this as being a basic thing) wanted to be able to place and organise the extra fields exactly as I wanted them as opposed to how the code would dictate I should have them.

    The site itself, despite the sound of my enquiries, is actually a very simple one. I would agree that some of the most simple are the most successful, but in the same breath I wouldnt hesitate to point out that this means simple for the user to use and not simple as in thrown together in a cooking pot and hoping for the best.
    My intention is just to create a natural flow of information for the users, this way it would feel natural to them and little effort is ever required. If information begins to jump about (from my perspective) this would then induce confusion, which in turn leads users to become 'scared' per se. If this happens you then lose users instead of maintaining and increasing them.

    Fantastic example and testament to all of this is eBay. In the early years it was simple, hence numbers grew. Now ebay (and they claim its in the interests of the users to keep it simple etc and more secure) have begun making it A more complex, which backs up your point, and secondly information is scattered. Although still a highly usable site, you have to work hard in being able to use it properly and so now I know plenty of people abandoning ebay, heck I am one of them also.

    But yes, David, I agree simple is good karma, but I do not wish to confuse simple with 'Thrown together'. As an example the current display of info on a page would be as follows;

    Seller : Name
    City :
    State :
    Country :
    Price : $1
    Date Added :
    Expiration :
    Views :
    (Extra Field 1)Sale Type: Sell & Swaps Considered
    Extra Field 2)Price Flexability: ONO



    I would like to have:

    Title

    List Type: Sell & Consider Swap............................Seller
    Price: $1 (ONO(field))........................................City
    ..................................................................State
    xTra field.......................................................Expiration
    xTra field.......................................................Views
    xTra field etc

    Desc

    (sorry about the .............. but space didnt work lol)


    The main fields I dont think (think lol) would be a problem as these are hard coded.
    Its just those extra fields lol.

    Many thanks for listening to my ramblings on. With regards to hiring someone, if only I had the money to invest. I can't even go for the membership module at present or even the stop spam module due to a lack of funds. Besides I love knowing how it works :)

    Kindest regards,

Share This Page