Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Harry James
14,780 PointsKeeping Strings in one place
Hello there,
I was wondering what everyone's best methods were for keeping Strings in one localized location?
For example, if you designed your website with the name "NotVeryAwesomeSite" but later decided to call it "SuperAwesomeSite", is there a way to change this in one place and the change is then reflected everywhere, rather than having to find and replace?
Would love to hear everyone's ideas! :)
3 Answers
Jennifer Nordell
Treehouse TeacherThat sounds like a job for PHP! I can highly recommend the course here. You'll learn how to do that in just a few videos, I believe! I see you've started with PHP... just continue down that road. :)
Konrad Pilch
2,435 PointsThis is straight forward!
You make a variable, lets call it date.
Then you assign something to the variable.
ANd then you output the variable name, in this case date, wheere you want, and if you cahnge it in one place, in the variable assigment, it iwll change it everywhre.
Carlos Federico Puebla Larregle
21,074 PointsYou can do it with Flask creating a layout, like this:
<!doctype html>
<html>
<head>
<title>{% block title %}Flask Basics{% endblock %}</title>
<link rel="stylesheet" href="/static/styles.css">
</head>
<body>
{% block content %}
<p>Brought to you by the fine folks at Treehouse!</p>
{% endblock %}
{% block scripts %}{% endblock %}
</body>
</html>
Then you extend that "layout.html" in every other page that you need that and add the {{ super() }} block to use what ever is in the html that you are extending. Like this in an "index.html":
{% extends "layout.html" %}
{% block title %}Howdy! | {{ super() }}{% endblock %}
{% block content %}
<h1>Hello from {{ name }}!</h1>
{% endblock %}
So if you change what's in the title tag in the "layout.html" file, is going to be changed in the "index.html" file too. I hope that helps.
Harry James
14,780 PointsHarry James
14,780 PointsThanks Jennifer!
I found the course over here and did indeed learn how to do this in the first few video's.
Incredible that it took me so long to find a solution to this on the internet without going into the complications of localization, when it was just explained so simply here :)
Jennifer Nordell
Treehouse TeacherJennifer Nordell
Treehouse TeacherHarry James I know, right? It's one of the many reasons I'm so glad I started here. :)