Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8486487
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T20:57:30+00:00 2026-06-10T20:57:30+00:00

How to use the tal condition to check the file type and render the

  • 0

How to use the tal condition to check the file type and render the template in Plone 4.1

My file preview template rendering depends upon the file extension. If file extension is ‘pdf’, I wish to use something like this:(just started working with TAL, TALES, METAL)

<tal:define="file_nm global string:${here/absolute_url}"
<tal:condition="file_nm.slice[-3:] = 'pdf'">

    <embed width="100%" height="100%" name="plug-in" tal:attributes="src string:${here/absolute_url}#" 
         draggable="false" onselectstart="false"  />

else use :(for files other than ‘pdf’)

<IFRAME src="http://www.xyz.com" 
            tal:attributes="src string:${here/absolute_url}/rfpreview"
            ondragstart="false" onselectstart="false"
            width="100%" height="400" scrolling="auto" frameborder="0"></IFRAME>

Can someone guide me on the complete custom code snippet for custom view :atreal.richfile.preview.interfaces.ipreview-atreal.richfile.preview.viewlet

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T20:57:32+00:00Added an answer on June 10, 2026 at 8:57 pm

    TAL statements are attributes on existing tags. You can introduce dummy elements with the tal: namespace prefix, but the statements like define and condition need to expressed as attributes still.

    Also, the default TALES expression type is path expressions, but you want to use python expressions. That’s fine, but you need to specify them as such with the python: prefix.

    Last but not least, don’t use global unless you absolutely have to, which is really rarely. Defined names live in the scope of the XML element they are defined on, and don’t need to live on outside of these.

    Here is how I’d express the logic:

    <tal:block define="ispdf python:here.absolute_url().endswith('.pdf')">
    
        <embed width="100%" height="100%" name="plug-in" 
             tal:condition="ispdf"
             tal:attributes="src string:${here/absolute_url}#" 
             draggable="false" onselectstart="false"  />
    
        <iframe src="http://www.xyz.com" 
             tal:condition="not:ispdf"
             tal:attributes="src string:${here/absolute_url}/rfpreview"
             ondragstart="false" onselectstart="false"
             width="100%" height="400" scrolling="auto" frameborder="0"></iframe>
    
    </tal:block>
    

    This introduces a new <tal:block> element to define the ispdf boolean variable, determined by a python expression. Then the two variants are switched on or off by the tal:condition attributes on each element based on that value being True or False.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know that for performance it's good practice to use nocall on a <tal:condition>
use C#,want to upload excel file on google doc. bellow syntax use to upload
I want to know how to use this tal:repeat in my case. For example,
use warnings; use Test::More; use File::Find::Rule; use Test::File::Find::Rule; my $rule = File::Find::Rule->file->name('*.pl')->not_grep(qr/^\s*use\s+strict;/m, sub {
I'm trying to translate text out of a template file in a Pyramid project.
Use case: 3rd party application wants to programatically monitor a text file being generated
I am trying to use Nuget Command line util to Pack a nuspec file.
I am working with NppToR as an extension allowing the use of notepad++ to
Use open syscall to write and create a file ,there's no attributes with the
Use Case Show a photo uploaded by the user in a square box with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.