[jifty-devel] UTF-8 in views

Jes jjjesss at gmail.com
Wed May 12 14:45:12 EDT 2010


El Wed, 12 May 2010 13:37:07 -0400
Jesse Vincent <jesse at bestpractical.com> escribió:

> 
> 
> 
> On Wed, May 12, 2010 at 07:18:08PM +0200, Jes wrote:
> > Hi all:
> > 
> > I'm very confused about UTF-8 in html views. I can't get Jifty show
> > good UTF-8 characters in my views. I need to display words with
> > accents (in spanish), and the only way to show them is use
> > ISO-8859-1 or ISO-8859-15 encondings in View.pm. But the problem
> > arises again when I have to display values from the database with
> > accents!! 
> > 
> > I know I'm doing something wrong but I can't see it. 
> > 
> 
> Jes,
> 
> Can you put together a tiny sample app to show what you're seeing?
> _______________________________________________
> jifty-devel mailing list
> jifty-devel at lists.jifty.org
> http://lists.jifty.org/cgi-bin/mailman/listinfo/jifty-devel

Well, I'm not sure if I can attach a file to this message so I put the
code directly here. It's a View.pm only:

---------------------------------------------------------------------------------
package ImpactoWeb::View;
#################################################################################
#         FILE:  View.pm
#
#  DESCRIPTION:
#
#        FILES:  ---
#         BUGS:  ---
#        NOTES:  ---
#       AUTHOR:  YOUR NAME (),
#      COMPANY:
#      VERSION:  1.0
#      CREATED:  28/10/09 18:30:22
#     REVISION:  ---
################################################################################
use strict;
use warnings;
use Encode;

use Jifty::View::Declare -base;

################################################
#Desactivar saludo (muy feo)
private template salutation => sub { };

#template 'index.html' => page {
#
#};

################################################
#Raiz, por defecto mostramos lista de incidencias
template '/' => page {

        div {
            attr { class => "comments" } h2 {
                attr { id => "rounded" } 'Evaluación de Impacto';
            };
        }
    }

    show 'footer';

};


private template footer => sub {
    div {
        attr { id => 'footer' }

          table {
            cell {
                img { attr { src => '/static/img/logo.png' } };
            };
            cell {
                b { "Evaluación de Impacto para Incidencias en Red de
          Acceso " }; 
                p {
                    "Jesús Manuel Mariño Valcarce"; };

            }
          };
    };
};

1;
---------------------------------------------------------------------------------

As you can see there are words with accents and the special "n"
character that only exists in Spanish. Well, if you save this piece
with UTF-8 encoding then the words are not well displayed. If saved
with ISO-8859-1 then no problem. My app is now a mix of UTF-8 and
ISO-8859-1 (UTF-8 most of the files, and ISO-8859-1 in files like
View.pm that have to display HTML code). Everything ok until I have to
display values from the database. For example, in View.pm displaying a
table in which some column is a value obtained from the database. This
value is obtained with Jifty::DBI, the database is MYSQL. I guess the
data come in UTF-8 and for that reason my app is not able to display
well formed (when the value contains letters with accents). 

Jesse, you asked for a tiny app. If this piece of code is not suitable
I'll send a complete tiny app, but how can I send you?, zipped and
attached in a message to the list?

Thanks in advance.

Jes



More information about the jifty-devel mailing list