Tips for creating varied menu item sizes on different pagesHere are some techniques for altering

I've started working on a new blog with a few pages including Home and New post.

My aim is to have different font sizes for the titles on these pages. Specifically, I want the "Home" title to be size 45 and the "New post" title to be size 24 on the "index" page. On the "new" page, I want this to be reversed. How can I achieve this? Should I specify something in the "base" file or do I need to make changes in the "new" file?

Here are some screenshots of the website: https://i.sstatic.net/oaRPV.png https://i.sstatic.net/QGi9l.png Below is the code:

__base.html

$def with (page)

<html>
<head>
    <title>S. Gera | Vision</title>
<style>
    #menu {
        width: 200px;
        float: right;
    }
</style>
</head>
<body>

<ul id="menu">
    <li><a style="font-size: 45; text-decoration: none" href="/">Home</a></li>
<li><a style="font-size: 24; text-decoration: none" href="/new">New Post</a></li>
</ul>

$:page

</body>
</html>

__index.html

$def with (posts)

<html>
<h1 style="color: Grey; font-family: Georgia; text-align: Left">Blog posts</h1>

<ul>
$for post in posts:
    <li>
        <strong> <a style="color: Black; text-decoration: none; font-size: 18" href="/view/$post.id">$post.title</a> </strong>
        <a style="color: Blue; font-size: 15">| $datestr(post.posted_on)</a>
        <a style="color: Red; font-size: 11; font-family: Arial; text-decoration: none" href="/edit/$post.id">(Edit)</a>
    </li>
</ul>
</html>

__new.html

$def with (form)

<html>
<h1 style="color: Grey; font-family: Georgia; text-align: Left">New Blog Post</h1>

<form action="" method="post">
$:form.render()
</form>
<html>

__view.html

$def with (post)

<h1>$post.title</h1>
$datestr(post.posted_on)<br/>

$post.content

__edit.html

$def with (post, form)

<html>
<h1>Edit $form.d.title</h1>

<form action="" method="post">
$:form.render()
</form>


<h2>Delete post</h2>
<form action="/delete/$post.id" method="post">
    <input type="submit" value="Delete post"/>
</form>
</html>

Answer №1

If you're looking to have a common base but perform different actions depending on the template being used, it's important to parameterize the base and specify the desired value in the template file to be utilized in the base.

For instance, imagine modifying the base so that each menu item is assigned a class. If page.selected_menu matches, then the class is set to active; otherwise, the class is set to an empty string.

=== base.html ===
...
<ul id="menu">
<li>
   <a class="$('active' if page.selected_menu == 'home' else '')"  
      href="/">Home</a></li>
<li>
   <a class=$('active' if page.selected_menu == 'new' else '')"
      href="/new">New Post</a></li>
</ul>
...

Employ CSS to visually distinguish ul>li>a.active from ul>li>a.

Then, in your templates, designate the menu item you wish to mark as "active". For example:

=== new.html ===
$var selected_menu: new

=== home.html ===
$var selected_menu: home

var variables outlined in templates are accessible as attributes within the base template.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Which specific HTML element triggers the initiation of ajax in Jquery?

I have a situation where various HTML elements trigger ajax requests when clicked. My goal is to determine which specific element was clicked inside the ajaxComplete event. Although I attempted to use event.target, it only returns the entire document inst ...

What is the best way to automatically adjust the size of this HTML Menu to match the width of its

I am in the process of converting a Drupal 6 theme to Drupal 7 and I'm encountering some difficulties with this particular section. Below is the HTML code snippet: <ul id="nav" class=" scaling-active scaling-ready"> <li><a href="/demos ...

Tracking Time Spent in a Tab using HTML and JavaScript

I have a unique issue that requires a specific solution. Despite my extensive search across the internet, no useful answers were found. This is the snippet of HTML code in question: <form action="/timer.php" method="POST"> <span>Fir ...

Spin the div towards the location of the mouse

Is it possible to create a rotating effect on a div element based on the position of the mouse pointer? I envision the div displaying <- when the mouse is on the left side, and -> when the mouse moves to the right, regardless of direction. If anyon ...

Image Animation Using a Rotational Control (HTML/JavaScript/...)

I am interested in achieving a specific effect with a series of images that transition from dark to light. My idea is to have a dial or slider underneath or over the frame so that when it is moved to the left, the black image is displayed, and when moved t ...

The Gusser Game does not refresh the page upon reaching Game Over

Hi there, I am a beginner in the world of JavaScript and currently working on developing a small guessing game app. However, I have encountered an issue where the page is not reloading after the game is over and the 'Play Again' button appears to ...

The navbar links in Bootstrap 4 may be hidden, but the navbar brand still remains visible

I have implemented this code for my website's navbar, however, upon running it, I noticed that the navigation links are not visible. The navbar brand name "test" appears correctly, but the other links seem to be hidden. Does anyone have any insights o ...

Using justify-content-between in a div container with only two items will not produce the desired effect

I'm having trouble aligning two elements on opposite ends of a div container using Bootstrap's justify-content-between class. The h4 element is not on the left and the button on the right as expected. I am using Bootstrap 5.2.3. Can anyone help m ...

Adjust the height of a div based on the font size and number of lines

I'm trying to create a function that automatically sets the height of a div by counting lines. I managed to get it partially working, but then it stopped. Can someone please help me with this? function set_height() { var div_obj=document.getEleme ...

The Jquery css function does not support the setting of CSS3 variables

Hello there, I'm currently experimenting with CSS3 variables to adjust elements and various other things dynamically, but I've run into an issue where JQuery's css method seems to ignore any attempt to set a CSS variable. Here is what I&apo ...

jquery ajax request not functioning properly on Firefox browser

This query is following up on this inquiry and this one. I am experiencing difficulties sending form field values through the jquery ajax API. Here is the code snippet: index.html <!DOCTYPE html> <html> <head> <meta content="tex ...

Find the text on the webpage and click on it using Eclipse Selenium

I am trying to search for specific text within a webpage that is contained in a list. For each item in the list, I want to locate the text on the webpage and click on a corresponding button. This is the code I have been using: List<String> lstFatur ...

Working with JQuery to extract and append data stored in a JSON object

I am working with the following JSON data: [ { "MOD_AXL": 0, "MOD_CDS_ID": 110000168, "MOD_CV": 0, "MOD_CV_CTM": null, "MOD_ID": 168, "MOD_MFA_ID": 514, "MOD_PC": 1, "MOD_PCON_END": 199007, "MOD_PCON_START": 196303, ...

transition effect on div inside a link element upon hovering

My navigation menu currently looks like this: <nav> <ul> <li> <a href="#">About</a> <div style="background-color: #c03546;height: 10px;"></div> </li> <li> ...

Creating a visually appealing layout by positioning two images in opposite corners of a single div

As someone who's not well-versed in CSS, I could really use some assistance on creating a div with two images, similar to the diagram below. ...

Listening to audio on a mobile browser using an HTML audio element

What is the solution for the problem of playing audio on a mobile browser when it plays on a desktop browser but not on mobile? The code being used is: var audio = new Audio('sound.mp4') audio.play() ...

Lisp and HTML Scraping: A Powerful Combination

Looking for some guidance related to web scraping in Common Lisp, specifically in extracting data from a webpage. I am utilizing drakma for sending the http request and chtml for scraping the data. The webpage I am targeting is . Here's a snippet of t ...

Looking to keep the buttons within a Vue component fixed in place for easy switching?

I've implemented a Vue component called UserAuthentication that can switch between the signin and signup components. The component contains buttons for switching between signing in and signing up, which I want to be fixed on top of the form-box from b ...

Switching the horizontal tab design from Bootstrap 3 to Bootstrap 4

I'm currently working on adapting a code snippet from bootsnip that creates horizontal Bootstrap tabs with material-style design. I've encountered some challenges in converting it to Bootstrap 4, specifically in updating the CSS to use .nav-item ...

Ways to connect changing information with form fields utilizing ngModel

I am facing an issue with binding dynamic data to a list of input and select fields. Despite using ngModel for binding, only the entry from the last object is being displayed. Sample data that needs to be bound is as follows: properties=[ { "Id ...