| 1 |
lars |
1 |
<com:TContent ID="Main">
|
|
|
2 |
|
|
|
3 |
<h1>Using Themes and Skins</h1>
|
|
|
4 |
|
|
|
5 |
<p>
|
|
|
6 |
PRADO has intrinsic support for <a href="http://www.pradosoft.com/demos/quickstart/?page=Advanced.Themes">themes</a>. By using themes, we can better separate logic and presentation, and we can also change the overall appearance of our blog system more easily.
|
|
|
7 |
</p>
|
|
|
8 |
|
|
|
9 |
<h2>Creating Theme</h2>
|
|
|
10 |
|
|
|
11 |
<p>
|
|
|
12 |
We first create a new directory <tt>themes</tt>. This is the parent directory of all themes for a particular PRADO application. Any subdirectory under this directory will become a theme whose name is the subdirectory name.
|
|
|
13 |
</p>
|
|
|
14 |
|
|
|
15 |
<p>
|
|
|
16 |
To create a theme named <tt>Basic</tt>, we create a subdirectory <tt>theme/Basic</tt>. Under this directory, we may place theme-dependent stylesheet files, Javascript files, images, and skin files.
|
|
|
17 |
</p>
|
|
|
18 |
|
|
|
19 |
<com:InfoBox>
|
|
|
20 |
The <tt>themes</tt> directory must be Web-accessible, like the <tt>assets</tt> directory. Do not place sensitive data files under this directory. You can change the name or location of this directory by configuring the <a href="http://www.pradosoft.com/docs/classdoc/TThemeManager">TThemeManager</a> module in the application configuration.
|
|
|
21 |
</com:InfoBox>
|
|
|
22 |
|
|
|
23 |
|
|
|
24 |
<h3>Creating Stylesheet File</h2>
|
|
|
25 |
|
|
|
26 |
<p>
|
|
|
27 |
Under the <tt>themes/Basic</tt> directory, we create a CSS stylesheet file named <tt>style.css</tt>. When a page uses this theme, PRADO will automatically import this stylesheet to the page. The same occurs for Javascript files.
|
|
|
28 |
</p>
|
|
|
29 |
|
|
|
30 |
<p>
|
|
|
31 |
The CSS file is shown as follows.
|
|
|
32 |
</p>
|
|
|
33 |
|
|
|
34 |
<com:TTextHighlighter CssClass="source">
|
|
|
35 |
body {
|
|
|
36 |
font-family: verdana, 'trebuchet ms', sans-serif;
|
|
|
37 |
font-size: 10pt;
|
|
|
38 |
background: white;
|
|
|
39 |
}
|
|
|
40 |
#page {
|
|
|
41 |
margin: 0 auto 0 auto;
|
|
|
42 |
width: 600px;
|
|
|
43 |
}
|
|
|
44 |
#footer {
|
|
|
45 |
text-align: center;
|
|
|
46 |
margin-top: 10px;
|
|
|
47 |
padding: 10px;
|
|
|
48 |
border-top: 1px solid silver;
|
|
|
49 |
}
|
|
|
50 |
.post-box {
|
|
|
51 |
margin-bottom: 10px;
|
|
|
52 |
padding: 5px;
|
|
|
53 |
}
|
|
|
54 |
.post-box h3 {
|
|
|
55 |
padding: 5px;
|
|
|
56 |
font-size: 13pt;
|
|
|
57 |
background: lightgray;
|
|
|
58 |
}
|
|
|
59 |
.post-box a {
|
|
|
60 |
color: black;
|
|
|
61 |
text-decoration: none;
|
|
|
62 |
}
|
|
|
63 |
.post-box a:hover {
|
|
|
64 |
color: red;
|
|
|
65 |
}
|
|
|
66 |
</com:TTextHighlighter>
|
|
|
67 |
|
|
|
68 |
|
|
|
69 |
<h3>Creating Skin File</h2>
|
|
|
70 |
|
|
|
71 |
<p>
|
|
|
72 |
We use skins to initialize the properties of PRADO controls. Skins are stored as skin files (suffix name <tt>.skin</tt>) under a theme directory. Each skin file can contain multiple skins for one or several types of control.
|
|
|
73 |
</p>
|
|
|
74 |
|
|
|
75 |
<p>
|
|
|
76 |
As a test, we will try to create a skin that changes the background color of the link buttons in the page footer. We create a file named <tt>button.skin</tt> under the theme directory <tt>themes/Basic</tt>.
|
|
|
77 |
</p>
|
|
|
78 |
|
|
|
79 |
<com:TTextHighlighter CssClass="source" Language="prado">
|
|
|
80 |
<com:THyperLink SkinID="MainMenu" BackColor="lightgreen" />
|
|
|
81 |
</com:TTextHighlighter>
|
|
|
82 |
|
|
|
83 |
<p>
|
|
|
84 |
The <tt>button.skin</tt> skin file contains only one skin for <tt>THyperLink</tt> controls whose <tt>SkinID</tt> property is <tt>MainMenu</tt>. The skin sets the background color of the control to be light-green.
|
|
|
85 |
</p>
|
|
|
86 |
|
|
|
87 |
<p>
|
|
|
88 |
Accordingly, we need to modify <tt>protected/common/MainLayout.tpl</tt> so that the link buttons in the footer use <tt>MainMenu</tt> as their <tt>SkinID</tt>.
|
|
|
89 |
</p>
|
|
|
90 |
<com:TTextHighlighter CssClass="source" Language="prado">
|
|
|
91 |
......
|
|
|
92 |
<div id="footer">
|
|
|
93 |
......
|
|
|
94 |
<com:THyperLink Text="Home" SkinID="MainMenu"
|
|
|
95 |
NavigateUrl="<%= $this->Service->DefaultPageUrl %>" />
|
|
|
96 |
|
|
|
97 |
<com:THyperLink Text="New Post" SkinID="MainMenu"
|
|
|
98 |
NavigateUrl="<%= $this->Service->constructUrl('posts.NewPost') %>"
|
|
|
99 |
Visible="<%= !$this->User->IsGuest %>" />
|
|
|
100 |
......
|
|
|
101 |
</div>
|
|
|
102 |
......
|
|
|
103 |
</com:TTextHighlighter>
|
|
|
104 |
|
|
|
105 |
<com:InfoBox>
|
|
|
106 |
The syntax for skin files is very similar to that of PRADO templates. Each <tt><com:></tt> tag defines a skin for a particular type of control. PRADO automatically aggregates all skin files in a theme and applies them when a themed page is being rendered.
|
|
|
107 |
</com:InfoBox>
|
|
|
108 |
|
|
|
109 |
|
|
|
110 |
<h2>Using Theme</h2>
|
|
|
111 |
|
|
|
112 |
<p>
|
|
|
113 |
To use the theme we just created, we modify the application configuration as follows. As we see, the <tt>Theme</tt> property for all pages is set as <tt>Basic</tt>, the name of the theme we created.
|
|
|
114 |
</p>
|
|
|
115 |
|
|
|
116 |
<com:TTextHighlighter CssClass="source" Language="xml">
|
|
|
117 |
......
|
|
|
118 |
<services>
|
|
|
119 |
<service id="page" class="TPageService" DefaultPage="posts.ListPost">
|
|
|
120 |
<pages MasterClass="Application.layouts.MainLayout" Theme="Basic" />
|
|
|
121 |
</service>
|
|
|
122 |
</services>
|
|
|
123 |
......
|
|
|
124 |
</com:TTextHighlighter>
|
|
|
125 |
|
|
|
126 |
<com:InfoBox>
|
|
|
127 |
It is possible to specify different themes for different pages, and this can be done either in application/page configurations or programmatically (note <tt>Theme</tt> a page property). For the latter, it is must be done in <tt>onPreInit()</tt> method of the page because PRADO applies a theme to a page early in the page lifecycle.
|
|
|
128 |
</com:InfoBox>
|
|
|
129 |
|
|
|
130 |
|
|
|
131 |
<h2>Testing</h2>
|
|
|
132 |
<p>
|
|
|
133 |
To see how our blog pages look like, visit the URL <tt>http://hostname/blog/index.php</tt>. We shall see the font, layout, borders are changed in the page. Also, the link buttons in the footer have light-green background.
|
|
|
134 |
</p>
|
|
|
135 |
|
|
|
136 |
<img src="<%~ output.gif %>" class="output" />
|
|
|
137 |
|
|
|
138 |
</com:TContent>
|