Modules, themes and dictionaries

564 views
Skip to first unread message

"José A. Accino"

unread,
Jan 1, 2009, 4:21:51 PM1/1/09
to simple...@googlegroups.com

I have just moved to the latest trunk, and replaced my old login-pgsql
authentication plugin with the included sqlauth module.

The authentication itself goes fine with that one, but the custom login
form template I was using, became lost in the process, so I have
attempted to put it on a themes module.

(BTW, the modules page doesn't look very illustrative about those moves.
At first glance is not clear where should I put my templates: maybe in a
templates/ directory on sqlauth? within a theme module? Why not just to
use a /themes/ directory on the simplesamlphp root level instead of that
convoluted "modules/<thememodule>/themes/<theme>/<module>/<template>" path?)

Anyway, I was able finally to put my login form template in a
modules/custom/themes/avgreen/core/ path to replace the core
loginuserpass.php one and it displays right on login. My images and css
sheets run fine, too (they are in www/resources/ yet, however. Maybe
I'll have to look soon for another location).

However, the translation of texts and prompts fails and I get those "not
translated (login:username)" instead. It looks as the dictionaries
lookup fails while using a module theme.


Any ideas?


José Alfonso.

Andreas Åkre Solberg

unread,
Jan 2, 2009, 4:48:10 AM1/2/09
to simple...@googlegroups.com, "José A. Accino"
On 1. jan.2009, at 22:21, José A. Accino wrote:

(BTW, the modules page doesn't look very illustrative about those moves. 
At first glance is not clear where should I put my templates: maybe in a 
templates/ directory on sqlauth? within a theme module? Why not just to 
use a /themes/ directory on the simplesamlphp root level instead of that 
convoluted "modules/<thememodule>/themes/<theme>/<module>/<template>" path?)

Anyway, I was able finally to put my login form template in a 
modules/custom/themes/avgreen/core/ path to replace the core 
loginuserpass.php one and it displays right on login. My images and css 
sheets run fine, too (they are in www/resources/ yet, however. Maybe 
I'll have to look soon for another location).

First, you are right, the way of making themes has not earlier been documented very well. At first glance (at least without documentation) the directory structure may be confusing.

I've written a short document to try to explain how to make themes in simpleSAMLphp both by adding themes in the core templates/ folder, but also by inclduing a theme in a module.

Let me know if this document makes sense to you:

However, the translation of texts and prompts fails and I get those "not 
translated (login:username)" instead. It looks as the dictionaries 
lookup fails while using a module theme.

Translation relates to the dictionaries/ files. If you want to override the login template in your theme in general you shold not need to modify the language tags, but reuse the ones that exists there.

If you need to add text or modify text, you can do it the following way (if I remember correctly):

if the login templates include references like this {login:wronguserpass}, you can in your themed login template file:
modules/customui/themes/avgreen/default/login.php

add references like this {customui:login:wrongpass}

and then include a dictionary file in your module, like this:
modules/customui/dictionary/login.php

If this does not work, please send me your module folder (zipped), and I may look at it :)

BTW: Happy new year! 

Andreas


-- 
Andreas Åkre Solberg 
=andreas



Jose A. Accino

unread,
Jan 2, 2009, 7:21:43 AM1/2/09
to simple...@googlegroups.com

Hi, Andreas. Again at work? I didn't hope to see you before Jan 5 :-)


> Let me know if this document makes sense to you:
> http://rnd.feide.no/content/theming-simplesamlphp

Yes, of course. Actually, the mode you tell about in "Creating your
first theme" is the same one I was using before moving the
authentication to the modules approach.

Let us see it:

If I'm right, there are three sites, at least, to put our own
templates: in a theme directory in templates/ (in simplesamlphp root),
in a templates/ directory within the module, or in a custom theme module.

I have removed my PostgreSQL authentication plugin to start using the
included sqlauth module.

As soon as I configure our IdP to use the sqlauth module (after
setting config/authsources.php), the login process doesn't use the
files from the main templates/ directory anymore, where I had my
templates until now, but those from modules/core/templates.

Then, it seems that choosing to use the sqlauth module means I'm
forced to use the templates included in modules/core/templates/ as
well... or override them with a theme module. If I'm right, this is a
point that should be clearer in the documentation: what templates to
use with the modules or how to deal with modules when there is an
general custom theme in use.

So, although I had my custom theme defined in main templates/custom,
given that I want to use the sqlauth module, I have now to override
loginuserpass.php (not login.php) with something as
modules/custom/themes/avgreen/core/loginuserpass.php.

Any other alternative, as setting 'theme.use' =>'custom' and putting
loginuserpass.php template in the main templates/custom/ directory
triggers an error as:

Jan 02 13:04:10 simpleSAMLphp 6 [5873c9b460]
/simplesaml/module.php/core/loginuserpass.php - Template: Could not
find template file [core:loginuserpass.php] at
[/usr/local/www/simplesamlphp/modules/core/templates/custom/loginuserpass.php]
- now trying the base template

As you see, it's looking for loginuserpass.php template, but NOT in
the main templates/custom/ directory, where it is, but within the core
module itself.

This seems to mean also setting 'theme.use' => 'custom:avgreen' in
config.php, but then all remaining templates in the main
templates/custom are lost.

(IMHO, if 'theme.use' does not indicate a module with :, we should
look first an the main templates directory. Maybe we could use
'theme.use' =>':custom' to mean within the core module, so leaving
'theme.use' =>'custom' for the main one...)


> Translation relates to the dictionaries/ files. If you want to override
> the login template in your theme in general you shold not need to modify
> the language tags, but reuse the ones that exists there.

My loginuserpass.php template (in modules/custom/themes/avgreen/core/)
uses standard tags, as $this->t('login:user_pass_header'), so it
shouldn't need any special dictionary, but the standard one.
(login.php, in this case, it isn't?)

Any pointers about where to look in depth about that?

Thanks,
JA.


--
José Alfonso Accino
IT Systems Management
Central Computing Services
University of Málaga -Spain-

Andreas Åkre Solberg

unread,
Jan 5, 2009, 2:19:29 AM1/5/09
to simple...@googlegroups.com, "José Accino A."
On 2. jan.2009, at 13:21, Jose A. Accino wrote:

[snipp]

Jan 02 13:04:10 simpleSAMLphp 6 [5873c9b460]
/simplesaml/module.php/core/loginuserpass.php - Template: Could not
find template file [core:loginuserpass.php] at
[/usr/local/www/simplesamlphp/modules/core/templates/custom/loginuserpass.php]
- now trying the base template

As you see, it's looking for loginuserpass.php template, but NOT in
the main templates/custom/ directory, where it is, but within the core
module itself.

This seems to mean also setting 'theme.use' => 'custom:avgreen' in
config.php, but then all remaining templates in the main
templates/custom are lost.

You are right. The reason is that you cannot combine the two ways of creating themes. I would suggest that you do the following:

You have created your own module 'custom', which includes a theme named 'avgreen'. Then you have a directory structure like this:

simplesamlphp/modules/custom includes:
./default-enable
./themes
./themes/avgreen
./themes/avgreen/core
./themes/avgreen/core/loginuserpass.php
./themes/avgreen/default
./themes/avgreen/default/includes
./themes/avgreen/default/includes/header.php
./themes/avgreen/openid
./themes/avgreen/openid/consumer.php

As you see, you include a subfolder core, where you can override templates from the 'core' module. You may be confused by core versus default. 'default' is the non-modularized part of simplesamphp, while 'core' is the core module, including in example some basic username password authentication module templates.

If you have already created a theme 'the old way', by adding stuff in 'simplesamphp/templates/custom', I would reccomend to move all files from 'simplesamphp/templates/custom' into: 'simplesamphp/modules/custom/theme/avgreen/default/'.

And then leave the config to be:
'theme.use' => 'custom:avgreen'

Then everything should work, and you wil now have a directory 'custom' in the modules folder including all of your theme templates collected in one directory, easy to distribute and share to other installations.

Let me know if this works for you...?


(IMHO, if 'theme.use' does not indicate a module with :, we should
look first an the main templates directory. Maybe we could use
'theme.use' =>':custom' to mean within the core module, so leaving
'theme.use' =>'custom' for the main one...)

As it is now, you could specify: 
'theme.use' =>'feidernd'

which will use templates from simplesamlphp/templates/feidernd/

But this way of adding 'themes' will not allow you to override template files that is embedded in modules. Therefore I would say, the reccomended way of adding a theme would be to create a module, including a theme.

I will consider removing the first of the two methods of adding themes, as it is rather confusing to have several ways of doing things. The reason why we had to change the theming was because of the modularization approach of simplesamlphp.

Translation relates to the dictionaries/ files. If you want to override
the login template in your theme in general you shold not need to modify
the language tags, but reuse the ones that exists there.

My loginuserpass.php template (in modules/custom/themes/avgreen/core/)
uses standard tags, as $this->t('login:user_pass_header'), so it
shouldn't need any special dictionary, but the standard one.
(login.php, in this case, it isn't?)

Yes you are right!

Any pointers about where to look in depth about that?

Sorry, you are a bit ahead of us, we have not (yet) properly documented how third party developers should do localization (dictionaries), but here is a hint:

'login:user_pass_header',
will lookup the 'user_pass_header' header in the dictionary: 'simplesamlphp/dictionaries/login.php'

'custom:login:user_pass_header'
will lookup the 'user_pass_header' header in the dictionary: 'simplesamlphp/modules/custom/dictionaries/login.php'

Which means you cannot override dictionaries inside a custom module for built-in templates. If you want to override the dictionary for a built-in login module, you have two options:
1) Modify the simplesamlphp/dictionaries/login.php file. Not reccomended to override files included in the distribution, but still it could be the easiest way out in some situations.
2) Override the loginuserpass.php template with your own, and replace the references to dictionaries from login:user_pass_header to something like custom:login:user_pass_header.

Did this answer your question?

Jose A. Accino

unread,
Jan 5, 2009, 4:25:37 AM1/5/09
to simple...@googlegroups.com
Andreas Åkre Solberg wrote:

[...]


>
> You have created your own module 'custom', which includes a theme named
> 'avgreen'. Then you have a directory structure like this:
>
> simplesamlphp/modules/custom includes:
> ./default-enable
> ./themes
> ./themes/avgreen
> ./themes/avgreen/core
> ./themes/avgreen/core/loginuserpass.php
> ./themes/avgreen/default
> ./themes/avgreen/default/includes
> ./themes/avgreen/default/includes/header.php
> ./themes/avgreen/openid
> ./themes/avgreen/openid/consumer.php

No problem with a such scheme. Just a drawback, however: it looks as
I'd have to copy that 'default' subfolder into each new theme...


> Let me know if this works for you...?

Yes, the themes issue seems solved :-)


> 'login:user_pass_header',
> will lookup the 'user_pass_header' header in the dictionary:
> 'simplesamlphp/dictionaries/login.php'
>
> 'custom:login:user_pass_header'
> will lookup the 'user_pass_header' header in the dictionary:
> 'simplesamlphp/modules/custom/dictionaries/login.php'
>
> Which means you cannot override dictionaries inside a custom module for
> built-in templates.

I see now... However, I have done it so but it doesn't work. I have a
login.php dictionary in modules/custom/dictionaries/ (just a copy of
the default one):

#ll modules/custom/dictionaries/
total 18
-rw-r--r-- 1 www wheel 17589 5 ene 09:29 login.php

And I have modified the tags, as well, pointing to that custom dictionary:

<label><?php echo $this->t('custom:login:user_pass_text'); ?></label>

But I keep getting the "not translated (custom:login:user_pass_text)"
messages yet. This is the log:

Jan 05 10:20:00 simpleSAMLphp 6 [ee165364a6] Template: Looking up
[custom:login:user_pass_header]: not translated at all.
Jan 05 10:20:00 simpleSAMLphp 6 [ee165364a6] Template: Looking up
[custom:login:user_pass_text]: not translated at all.
Jan 05 10:20:00 simpleSAMLphp 6 [ee165364a6] Template: Looking up
[custom:login:username]: not translated at all.
Jan 05 10:20:00 simpleSAMLphp 6 [ee165364a6] Template: Looking up
[custom:login:password]: not translated at all.

Andreas Åkre Solberg

unread,
Jan 5, 2009, 7:03:31 AM1/5/09
to simple...@googlegroups.com

On 5. jan.2009, at 10:25, Jose A. Accino wrote:
>
> No problem with a such scheme. Just a drawback, however: it looks as
> I'd have to copy that 'default' subfolder into each new theme...

Hmm, what do you mean? It should not be neccessary to move any default
templates, unless you want to modify them? Be sure that you do not
modify the
'theme.base' => 'default',

>> Which means you cannot override dictionaries inside a custom module
>> for
>> built-in templates.
>
> I see now... However, I have done it so but it doesn't work. I have a
> login.php dictionary in modules/custom/dictionaries/ (just a copy of
> the default one):

Hmm, can you try:

<?php echo $this->t('{custom:login:user_pass_text}'); ?>

and see if that works?

Jose A. Accino

unread,
Jan 5, 2009, 7:48:08 AM1/5/09
to simple...@googlegroups.com

Yes, now it works! :-)

Thanks!

Reply all
Reply to author
Forward
0 new messages