Jump to content

Two fields on a page - Best way to replace old field value with another one


nfil
 Share

Recommended Posts

Hello,

I have some doubts about what should be the best way to replace and output a value, replacing another one.

So I have two fields on a page, one with the old value and another with a new one, need to keep a old value in the backend and render the new one in the frontend and the old value would be blotted out.

Thank you for your help.

Link to comment
Share on other sites

Hello Macrura. Modified this from the skyscrapers profile to render the field for the current price (old value):

$out .= ($product->sc_price ? number_format($product->sc_price) . " €" : $na);

Then I created a new field sc_price_drop on a product template with a new price, how do I output the new price and show the old price blotted out?

Found this post that should relate to what I want to achieve, Diogo's and Nik's examples would be a way to replace a value with a new one, using selectors?

http://processwire.com/talk/topic/4860-selector-match-that-mixes-multiple-fields/?hl=replace#entry47228

thanks.

Link to comment
Share on other sites

you mean like this?

if($product->sc_price_drop) {
	$out .=  '<del>' . $product->sc_price . " €</del>"; 
	$out .= number_format($product->sc_price_drop) . " €";
	} else {
	$out .= ($product->sc_price ? number_format($product->sc_price) . " €" : $na);
}
  • Like 3
Link to comment
Share on other sites

thanks! Had some syntax error when I changed the function, now I have this:

$out .= "\n\t\t<td>"; 
	if($product->sc_price_drop) {
	$out .=  '<del>' . $product->sc_price . " €</del><br/>"; 
	$out .= number_format($product->sc_price_drop) . " €";
	} else {
	$out .= ($product->sc_price ? number_format($product->sc_price) . " €" : $na) . "</td>";
	}
	$out .= "\n\t\t<td>" . ($product->sc_sku ? $product->sc_sku : $na) . "</td>";

It works fine don't know if I should use the variable out with a dot before the equal sign (newbie question).

 
I made other site with different roles but in that case I had a template to lock pages to unregistered users, this case is different. 

This time what would be the best way to output a field value only to a group of users with a role named retailer?

Create a field named sc_price_retailer on the page with the other price values and the new sc_price_retailer field, then when a user logs in with a retailer account they can view the only sc_price_retailer field value. Would that be possible?

Link to comment
Share on other sites

It works fine don't know if I should use the variable out with a dot before the equal sign (newbie question).

The dot concatenates the strings from left and right of the operator:

$string = "Team"; // "Team"
$string .= " Building"; // "Team Building"
$string .= " Exercise"; // "Team Building Exercise"
$string .= " '99"; // "Team Building Exercise '99"
 

So, in your code you have to use the dot, except on the first $out assuming that the variable is empty. If the $out comes from previous code and is already populated,  then you should keep also that dot.

  • Like 2
Link to comment
Share on other sites

Diogo the logic makes sense. Only used the dot on the same line of the variable but the function is correct there is a populated $out before those.

That was a very nice tutorial on php syntax for beginners like me. Thanks for de detailed explanation of the logic. 

Still wonder what should be the best option for this:

I made other site with different roles but in that case I had a template to lock pages to unregistered users, this case is different. 

This time what would be the best way to output a field value only to a group of users with a role named retailer?

Create a field named sc_price_retailer on the page with the other price values and the new sc_price_retailer field, then when a user logs in with a retailer account they can view the only sc_price_retailer field value. Would that be possible?

will have a look here! http://processwire.com/api/selectors/inputfield-dependencies/

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...