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; I think we are saying the same thing. You need to do the logic from within the smarty plugin. you ...


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

Reply
 
Thread Tools Display Modes
Old 08-24-2010, 05:05 PM   #31
All Hands On Deck
 
 
Join Date: Mar 2008
Posts: 2,775
Rep Power: 67
seymourjames is a jewel in the rough
Default

I think we are saying the same thing. You need to do the logic from within the smarty plugin. you may even need to make various versions of it for the different cases you have.
__________________
"The fool doth think he is wise, but the wise man knows himself to be a fool.".

TemplateCodes.com for 68 Classifieds

Last edited by seymourjames; 08-24-2010 at 05:54 PM.
seymourjames is offline   Reply With Quote
Old 08-25-2010, 06:03 AM   #32
Customer
 
Join Date: Jul 2010
Posts: 4
Rep Power: 0
KLOUGOON is on a distinguished road
Default

Quote:
Originally Posted by Mike-N-Tosh
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 Code:
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 Code:
If($value<>"")
{
    
$output $ftitle': ' .$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}
Hi Mike,

Sorry for the belated response but a very sincere thankyou for your reply. I have been offline due to switching servers but have just had a chance to test the code and it works like a charm. I have to say this community is the best I have come across for support and willingness to help others. Thanks again.

Cheers Kris
KLOUGOON is offline   Reply With Quote
Old 08-25-2010, 09:07 AM   #33
Customer
 
Join Date: Aug 2010
Posts: 59
Rep Power: 2
T0m1 is on a distinguished road
Default

Ok I have to admit I am completely stumped lol.

My problem is that id id need to include a plugin into a plugin as well as a variable to putput the desired result. The problem is obviously that plugins are standalone php files.

Ive read near enough the entire smarty documentation and the only thing that would come close to allowing me to achieve my result would be the capture tag as originally tried by Kris, which likewise didnt work.

Im just trying to figure out, how I could assign the output of "get_extra_fields2 id=$view fid=8" to a variable as this then surely should allow me to place the variable inside of a conditional statement within the tpl file.

Basically, (as looking back im not sure if I came across as well explained as I had imagined? ) what im hoping to achieve is this.

SelectB 1 has entries "To Give Away" and "Sell"
SelectB 2 has entries "ONO" "OVNO" "Open to Offers" and "No Offers"

If a user chooses "To Give Away" from SelectB 1 then output = To Give Away

else if a user chooses "Sell" from SelectB 1 then output = $price|format_money [value of SelectB 2]

Anyway Apologies if this wasnt explained to well earlier on (sometimes I tend to skimp over things when im busy on something).

Kindest regards,
__________________
Tom.

68c Developer v4.1.10 - Custom Template (in progress)
MySQL v5.0.91-community <-> PHP v5.2.13 <-> Apache v2.2.15
T0m1 is online now   Reply With Quote
Old 08-25-2010, 10:23 AM   #34
curmudgeon
 
Join Date: Mar 2006
Posts: 5,274
Rep Power: 129
Lhotch is a glorious beacon of light Lhotch is a glorious beacon of light Lhotch is a glorious beacon of light
Default

Quote:
Originally Posted by T0m1
Im just trying to figure out, how I could assign the output of "get_extra_fields2 id=$view fid=8" to a variable as this then surely should allow me to place the variable inside of a conditional statement within the tpl file.
Im confused as to why you are confused.

Look at the plugin, what dohees it do? It takes the $view variable which is the id of the ad and the $fid which is the id of the extra field you want, it uses them in a database query and gets the value from the database and assigns it to a PHP variables called $value and then that variable ie returned to the code framework that handles the plugins and then the value of the extra field you requested via {get_extra_fields2 id=$view fid=8} is displayed in the template.

Lets break this down into plain english and concentrate on just a single extra field.

What KIND of extra field is it?

What kind of logic are you looking to perform?

what do you want the final output to be?
__________________
Larry

Knowledge learned is more valuable than knowledge given.
Lhotch is offline   Reply With Quote
Old 08-25-2010, 11:15 AM   #35
Customer
 
Join Date: Aug 2010
Posts: 59
Rep Power: 2
T0m1 is on a distinguished road
Default

Quote:
Originally Posted by Lhotch
Im confused as to why you are confused.

Look at the plugin, what dohees it do? It takes the $view variable which is the id of the ad and the $fid which is the id of the extra field you want, it uses them in a database query and gets the value from the database and assigns it to a PHP variables called $value and then that variable ie returned to the code framework that handles the plugins and then the value of the extra field you requested via {get_extra_fields2 id=$view fid=8} is displayed in the template.

Lets break this down into plain english and concentrate on just a single extra field.

What KIND of extra field is it?

What kind of logic are you looking to perform?

what do you want the final output to be?
Hi Larry,

I guess im seriously confused because ive only just begun learning pure php and this would be bad enough, smarty as we know adds another layer to this and by the looks of it relatively rigid.

Anyway, in answer to your questions/scenario above.

What KIND of extra field is it?
Drop Down List

What kind of logic are you looking to perform?
IF elseIf Else statements
==
!=

what do you want the final output to be?
If the == is met then predefined text (or whatever is inside of the If section fo the condition)
If the != is met, (or the == is not met) then another variable and text (inside of the else section of the condition).

So to elaborate on your last question, lets please imagine dropdownlist to be a variable $dropdownlist . Ideally this is how id like it to work

{if $dropdownlist =="Give Away"}

Free to Good Home

{elseif $dropdownlist =="Sell"}

{$price|format_money}

{/if}

(I know I do not need to use an elseif and could simply have {else} I merely used it as an ideal solution).

I think this person was trying for exactly the same solution, but unfortunately the thread trailed off? extra field variable not evaluated

Many thanks Larry for your help Larry, it is very much appreciated,

Kindest regards,
__________________
Tom.

68c Developer v4.1.10 - Custom Template (in progress)
MySQL v5.0.91-community <-> PHP v5.2.13 <-> Apache v2.2.15
T0m1 is online now   Reply With Quote
Old 08-25-2010, 11:24 AM   #36
curmudgeon
 
Join Date: Mar 2006
Posts: 5,274
Rep Power: 129
Lhotch is a glorious beacon of light Lhotch is a glorious beacon of light Lhotch is a glorious beacon of light
Default

Okay, so once again goto the pluging itself. We see the database query and the result of that query is put into a variablecalled $value so all you need to do is apply your above logic to the variable value and alter it if needed before "returning" it.

near the bottom of the pluging you have

PHP Code:
return $value 
evaluate and perform logic on $value and proceed as needed...

PHP Code:
if($value =="Give Away"){
$value "Free to Good Home";
}elseif(
$value =="Sell"){
$value '{$price|format_money}';
}
return 
$value
I havent tested it and the {$price|format_money} may throw a wrinkle in there because it may not be parsed by smarty.
__________________
Larry

Knowledge learned is more valuable than knowledge given.
Lhotch is offline   Reply With Quote
Old 08-25-2010, 11:53 AM   #37
Customer
 
Join Date: Aug 2010
Posts: 59
Rep Power: 2
T0m1 is on a distinguished road
Default

Hi Larry,

That code partly works

The if statements now show 'Free to Good Home' if Give Away is selected and then goes to show the price if not.
But the output appears as {$price|format_money} on the front end.

So we are part of the way there Now the only thing left to figure out is how to delay the processing of the variable until it is outputted...

Kindest regards,
__________________
Tom.

68c Developer v4.1.10 - Custom Template (in progress)
MySQL v5.0.91-community <-> PHP v5.2.13 <-> Apache v2.2.15
T0m1 is online now   Reply With Quote
Old 08-25-2010, 12:26 PM   #38
curmudgeon
 
Join Date: Mar 2006
Posts: 5,274
Rep Power: 129
Lhotch is a glorious beacon of light Lhotch is a glorious beacon of light Lhotch is a glorious beacon of light
Default

Quote:
Originally Posted by T0m1
Hi Larry,

That code partly works

The if statements now show 'Free to Good Home' if Give Away is selected and then goes to show the price if not.
But the output appears as {$price|format_money} on the front end.

So we are part of the way there Now the only thing left to figure out is how to delay the processing of the variable until it is outputted...

Kindest regards,
As I eluded to in the last line of my above post, {$price|format_money} is being inserted into the template and is not being parsed so therefor it wont work.

Honestly what I would probably do is simply set the extra fields to appear in the listing and then just remove the section from the template that displays them. That way they will still be available as smarty vars and you can evaluate them at the template level.
__________________
Larry

Knowledge learned is more valuable than knowledge given.
Lhotch is offline   Reply With Quote
Old 08-25-2010, 12:46 PM   #39
Customer
 
Join Date: Aug 2010
Posts: 59
Rep Power: 2
T0m1 is on a distinguished road
Default

Indeed you did say that and I would not have thought otherwise.

You mentioned doing it at template level? How would I do this?

Many thanks
__________________
Tom.

68c Developer v4.1.10 - Custom Template (in progress)
MySQL v5.0.91-community <-> PHP v5.2.13 <-> Apache v2.2.15
T0m1 is online now   Reply With Quote
Old 08-26-2010, 04:50 AM   #40
Customer
 
Join Date: Aug 2010
Posts: 59
Rep Power: 2
T0m1 is on a distinguished road
Default

Hi Larry,

Ive been reading over and over what you mentioned above and im trying to understand it.
I can only (currently) understand it in 2 ways, 1 I create new tpl files and include these into the template?
Or the other I hide content from google and all other search engines (in effect so viewable by source view but not in browser output) which is a big no no, for me at least.

Kindest regards,
__________________
Tom.

68c Developer v4.1.10 - Custom Template (in progress)
MySQL v5.0.91-community <-> PHP v5.2.13 <-> Apache v2.2.15
T0m1 is online now   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 12:42 PM
extra fields in featured ads on home page rockabilly Technical Support 3 07-01-2009 05:02 AM
Extra Fields Showing Up On Search Page hotchops Technical Support 6 04-30-2009 09:34 PM
Extra Fields On View Listing Page dexignz Technical Support 1 09-23-2008 09:01 AM
extra fields on show results page anna245 Technical Support 3 04-18-2008 01:31 PM


All times are GMT -4. The time now is 09:12 PM.


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