Support Forums

Displaying variables and extra fields NOT already shown on the page

This is a discussion on Displaying variables and extra fields NOT already shown on the page within the Modules / Plugins / Modifications forums, part of the Developer Forums category; The question of can I display extrafields or certain variables on page where they are not present by default, is ...


Go Back   68 Classifieds Forums > Developer Forums > Modules / Plugins / Modifications

Reply
 
Thread Tools Display Modes
Old 07-04-2009, 09:19 AM   #1
All Hands On Deck
 
 
Join Date: Mar 2008
Posts: 3,445
Rep Power: 87
seymourjames is a jewel in the rough
Default Displaying variables and extra fields NOT already shown on the page

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.
__________________
"The fool doth think he is wise, but the wise man knows himself to be a fool.".

TemplateCodes.com for 68C
seymourjames is online now   Reply With Quote
Old 07-05-2009, 06:50 PM   #2
Member
 
Join Date: Jun 2009
Posts: 32
Rep Power: 11
vertyal is on a distinguished road
Default

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.
vertyal is offline   Reply With Quote
Old 07-05-2009, 06:55 PM   #3
Member
 
Join Date: Jun 2009
Posts: 32
Rep Power: 11
vertyal is on a distinguished road
Default

Sorry, I found $username under the $results variable....
Thanks for your help.
vertyal is offline   Reply With Quote
Old 05-16-2010, 01:50 PM   #4
Customer
 
Join Date: Jan 2010
Posts: 70
Rep Power: 9
metrony is on a distinguished road
Default

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.
__________________
Metro New York Apartments
Apartment listings for the Metro New York Area
metrony is offline   Reply With Quote
Old 05-16-2010, 03:39 PM   #5
All Hands On Deck
 
 
Join Date: Mar 2008
Posts: 3,445
Rep Power: 87
seymourjames is a jewel in the rough
Default

Look in the php manual on how to strip character and apply it within the plugin.
__________________
"The fool doth think he is wise, but the wise man knows himself to be a fool.".

TemplateCodes.com for 68C
seymourjames is online now   Reply With Quote
Old 05-16-2010, 10:23 PM   #6
TemplateCodes
 
TemplateCodes-Mike's Avatar
 
Join Date: Apr 2010
Posts: 40
Rep Power: 7
TemplateCodes-Mike is on a distinguished road
Default

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 Code:
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'];
    } 
__________________
TemplateCodes - Complete 68 Classifieds solutions and more
TemplateCodes-Mike is offline   Reply With Quote
Old 05-17-2010, 10:31 AM   #7
TemplateCodes
 
TemplateCodes-Mike's Avatar
 
Join Date: Apr 2010
Posts: 40
Rep Power: 7
TemplateCodes-Mike is on a distinguished road
Default

Quote:
Originally Posted by seymourjames
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.
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 Code:
{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.
__________________
TemplateCodes - Complete 68 Classifieds solutions and more
TemplateCodes-Mike is offline   Reply With Quote
Old 05-18-2010, 02:49 PM   #8
Customer
 
Join Date: Jan 2010
Posts: 70
Rep Power: 9
metrony is on a distinguished road
Default

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.
__________________
Metro New York Apartments
Apartment listings for the Metro New York Area

Last edited by metrony; 05-18-2010 at 02:52 PM.
metrony is offline   Reply With Quote
Old 08-20-2010, 01:46 AM   #9
Customer
 
Join Date: Jul 2010
Posts: 6
Rep Power: 0
KLOUGOON is on a distinguished road
Default

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}
KLOUGOON is offline   Reply With Quote
Old 08-20-2010, 05:50 AM   #10
Customer
 
Join Date: Aug 2010
Posts: 100
Rep Power: 8
T0m1 is on a distinguished road
Default

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,
__________________
Tom.

68c Developer v4.1.10 - Very Custom Template
MySQL v5.0.91-community <-> PHP v5.2.13 <-> Apache v2.2.15

Experience is the name we give to our mistakes
T0m1 is offline   Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
MODIFICATION: Display your extra fields on the showlistings.tpl page cwp Modules / Plugins / Modifications 28 08-06-2009 01:42 PM
extra fields in featured ads on home page rockabilly Technical Support 3 07-01-2009 06:02 AM
Extra Fields Showing Up On Search Page hotchops Technical Support 6 04-30-2009 10:34 PM
Extra Fields On View Listing Page dexignz Technical Support 1 09-23-2008 10:01 AM
extra fields on show results page anna245 Technical Support 3 04-18-2008 02:31 PM


All times are GMT -4. The time now is 05:57 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2011, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0