3 Replies - 495 Views - Last Post: 03 February 2012 - 02:19 PM

Topic Sponsor:

#1 Dastweeper  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 38
  • Joined: 13-July 11

How to dynamically change text sitewide?

Posted 02 February 2012 - 08:10 PM

Ok, so I was wondering:

If I have a passage of text like so,

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque pulvinar elementum nulla eget commodo. Fusce luctus auctor ultricies. Pellentesque feugiat gravida tristique. Nulla facilisi. Vestibulum placerat justo eget purus faucibus in tristique risus hendrerit. Praesent non porta velit. Sed suscipit, justo sit amet luctus cursus, turpis nulla fermentum ligula, ac lobortis purus lacus vitae lectus. Donec sed ligula nisi. ...Our price for that product, which is at $50.00... Duis et varius metus. Aenean quis turpis ut elit egestas hendrerit. Sed at eros magna, at egestas nisi. Aenean pulvinar fringilla consequat. Etiam eu dolor vel elit imperdiet consequat. In lobortis orci vel leo tristique egestas. Curabitur elementum turpis non ante mollis pellentesque. Maecenas varius neque quis nisi mollis consequat.

and I talk about that product a dozen or more other places on my site, is there a way to have each of the mentions of $50.00 be a reference to somewhere where I can easily change the value? So I can change the price and it'll be reflected sitewide?

Thanks.

Is This A Good Question/Topic? 0
  • +

Replies To: How to dynamically change text sitewide?

#2 e_i_pi  Icon User is offline

  • = -1
  • member icon

Reputation: 361
  • View blog
  • Posts: 1,020
  • Joined: 30-January 09

Re: How to dynamically change text sitewide?

Posted 02 February 2012 - 10:52 PM

That's called templating, and yes it can be done. There'a a variety of ways to do this, what sort of framework are you using?
Was This Post Helpful? 0
  • +
  • -

#3 Dastweeper  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 38
  • Joined: 13-July 11

Re: How to dynamically change text sitewide?

Posted 03 February 2012 - 12:14 PM

Just your basic HTML. Nothing fancy, but I can access MySQL if necessary.
Was This Post Helpful? 0
  • +
  • -

#4 e_i_pi  Icon User is offline

  • = -1
  • member icon

Reputation: 361
  • View blog
  • Posts: 1,020
  • Joined: 30-January 09

Re: How to dynamically change text sitewide?

Posted 03 February 2012 - 02:19 PM

I assume you're using a server-side scripting language as well then, since you have DB access.

One way to do this, for instance, would be to utilise global constants. Here's an example in PHP:
config.php
<?php
  define('OUR_PRICE', 50);
?>


index.php
<?php
  include 'config.php';
  echo 'Lorem ipsum blah blah. ';
  echo 'Our price for the product is $' . number_format(OUR_PRICE, 2, '.', ',');
?>


You can do it by storing the value in the DB as well, and then retrieving that value into a variable during script execution.

Either method is fine, but they are each suited to particular cases. Global constants are useful when you have a constant value that is never going to change, regardless of who the user is, or what they are doing. Variables read in from a DB are useful when there are conditions on what the value could be.

That's the basic premise but (of course as always with programming) you can use constants and variables in a multitude of ways, not just those I've described.

This post has been edited by e_i_pi: 03 February 2012 - 02:20 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1