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 7504291
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T21:31:32+00:00 2026-05-29T21:31:32+00:00

Is it a good idea to have/add logic inside a javascript template like so?

  • 0

Is it a good idea to have/add logic inside a javascript template like so?

<time style="display: <%= time ? 'block' : 'none' %>"><%= time %></time>

How is rendering time affected by this? Is a it big difference?

  • 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-05-29T21:31:36+00:00Added an answer on May 29, 2026 at 9:31 pm

    In general, it is wise to avoid logic in templates, although conditionally outputting a block if some value is initialized is ok.

    The following, I would not have a problem with:

    <% if(time) { %><time><%= time %></time><% } %>
    

    For your situation, I would do this. In your <head> (or css):

    <style>
      time:empty { display: none; }
    </style>
    

    In your template:

    <time><%= time %></time>
    

    I’m not certain about browser support for the `:empty´ pseudo-selector, but just to be safe you could also do:

    $("time:empty").hide();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How do you think, is it a good idea to have such an enum:
I have a good idea about Agile development process but I have no ieda
I would have liked to know if it was a good idea to return
If you have multiple, unrelated projects, is it a good idea to put them
Good morning all, I'm sure this is a gimme, but I have no idea
So I am making a basic log-in page. I have a good idea of
I have idea to implement my wpf windows like TabPages in tab control. It
I have often thought it would be a good idea to allow the use
Is it a good idea to use while loop instead of a cursor? What
When is it a good idea to use PHP_EOL ? I sometimes see this

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.