When combining Symfony, Twig, and Semantic UI, users may encounter an issue where the background image fails to display

Can someone assist me in identifying the issue with my code? I am using Symfony 2.8, Semantic UI, and Twig, attempting to set a background image on my site. The modification is being made to my base.html.twig file.

I have attempted:

  1. Using different images in various formats and sizes
  2. Placing the picture in different locations:
    • In app/Resources/views
    • In src/AppBundle/Resources/public/images
    • In web/semantic - where my Semantic UI files are kept
  3. Trying different methods of setting up:
    • As a body tag attribute
    • As inline style within the body tag
    • As internal style within a div tag
    • As external style - modifying the Semantic UI CSS

I have checked if there was a path name problem through multiple experiments, but that does not seem to be the issue. Interestingly, when setting a background color instead of an image, it works perfectly fine. Only the pictures do not show up.

Any suggestions on how to resolve this problem?

This is a snippet from my base.html.twig file:

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8" />
    <title>{% block title %} Address Book {% endblock %}</title>
    {% block stylesheets %}
        <link href="{{ asset('/semantic/semantic.css') }}" rel="stylesheet"/>
    {% endblock %}
    {% block javascripts %}
        <script src="{{ asset('/semantic/semantic.js') }}"></script>
    {% endblock %}
</head>
<body style="background-image:url(siano.jpg)">
    <div class="ui center aligned container">
        <div class="ui grid">
            <div class="four wide column"></div>
            <div class="eight wide column">
                <p>
                    <h1> Address Book </h1><br>
                </p>
                {% block body %}{% endblock %}
            </div>
            <div class="four wide column"></div>
        </div>
    </div>
</body>

The current file structure is as follows:

AppBundle
    Resources
        views
            base.html.twig
            siano.jpg

Answer №1

Here is a suggestion for you:

First, relocate your image to the web/images directory.

Then, update your code like this:

<body style="background-image:url('{{ asset('images/siano.jpg') }}')">
<div class="ui center aligned container">
    <div class="ui grid">
        <div class="four wide column"></div>
        <div class="eight wide column">
            <p>
                <h1> Address Book </h1><br>
            </p>
            {% block body %}{% endblock %}
        </div>
        <div class="four wide column"></div>
    </div>
</div>

Make sure to follow these steps and adjust your code accordingly.

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

Steps for creating a square button

Is it possible to create a square button on my website that still functions like a traditional button? I want the button to change appearance slightly when scrolled over. Currently, I have an example where the button is not clickable: http://jsfiddle.net ...

Display loading spinner and lock the page while a request is being processed via AJAX

Currently, I am working on a project using MVC in C#, along with Bootstrap and FontAwesome. The main objective of my project is to display a spinner and disable the page while waiting for an ajax request. Up until now, I have been able to achieve this go ...

Make the background image draggable while maintaining its size with background-size:cover

I'm working on a fixed div with an image as the background, set up like this: <div style=' width:230px; height:230px; background-repeat: no-repeat; background-image:url(img/myimage.jpeg) background-size: cover;'&g ...

SQL queries can be used in Node.js to fetch data from various tables and display it on an HTML page

I have a problem with my expressjs app where I am trying to count records from multiple tables in a database and display the results on separate divs in HTML. Currently, the code is functional without any errors, but I am encountering an issue where the sa ...

What is the best way to show the initial image within every div that has the class name .className?

I am looking to only show the first image in each div with the class name "className." This... <div class="className"> <p>Yo yo yo</p> <p><img src="snoop.jpg" /></p> </div> <div class="className"> Hel ...

Adjustable height for the absolute element

Having a bit of an issue with the height of the absolute div. About: .wrapper - I want the wrapper to automatically adjust its height but be limited by a max-height. (No scrolling for the wrapper) .title - Just a title .content - The problem aris ...

The individual blog pages on my site are not receiving the static files they need to display

I'm facing an issue serving a css file to individual blog posts on my website's blog section. Here's how it's supposed to work: Visit /blog- you'll see the main blog page, which is functioning fine. However, when trying to access ...

What is the process for fetching a specific image from a database folder by referencing its name?

We have a collection of images stored in the uploads folder within the root directory. Our goal is to display a single image for each user profile. Each user's profile image file name is saved in the database table called user under the field profile ...

How can I position the arrows inside the Slick Slider instead of outside?

After discovering how user-friendly slick slider is, I decided to incorporate it into a website I have been developing: You can find the slider positioned at the bottom of the page. However, I am facing an issue where I would like the navigation arrows to ...

The art of positioning images and creatively cropping

Seeking advice on allowing users to dynamically position and clip an image on a webpage. I've tried using CSS and JavaScript for clipping and resizing, but it's not working as expected. If PHP could provide a solution, that would be ideal for my ...

In search of a render function that can effectively apply styles to HTML strings using React JS

I have been struggling to convert the result field value, including HTML attributes string, into respective styles for one column in my antd table. Below is the string I am trying to convert: The exhaust air requirements for fume hoods will be based on m ...

What is the best way to manage classNames dynamically in React with Material-UI?

I am wondering how to dynamically add and remove classes from an img tag. My goal is to change the image automatically every 2 seconds, similar to Instagram's signup page. I am struggling to achieve this using the material-ui approach. Below is a snip ...

Interactive sidebar component with navigation and animated section markers

For weeks, I've been attempting to create a navigation sidebar similar to the ones shown in these images: Even though getbootstrap.com/components offers appealing navigation sidebars, I have not found a built-in component in their library. This has m ...

Creating React components with scoped CSS imports

I am facing an issue with my component's CSS structure and import method. About/style.css .AboutContainer { # Some style } p > code { # Some style } When importing the CSS in the component: About/index.js import './style.css&apos ...

Performing a database update in MySQL using user-generated data

I am looking to update the selected status timestamps in the corresponding column based on the user's selection from the menu. Explanation I have created columns in the database as shown below. Initially, the user will insert the sonumber and s ...

Discover the method for storing multiple values in local storage using a dictionary with JavaScript

I have a scenario in my code where I need to update a value without storing a new one. Let's say I need to input values in the following format: { firstname:'kuldeep', lastname:- 'patel' } After entering the values, they g ...

Having difficulty converting the string data to HTML using JavaScript in a Node.js Express application

In my app.js file, I will be sending data to an EJS file. app.get('/', function (req, res){ Blog.find({}, function(err, fountItems){ Blog.insertMany(defaultBlog, function(err){ }) } res.render( ...

Make the text in the SCSS file placeholder bold

Within my Angular front end application, there is a form containing a textarea: <mat-form-field class="full-width"> <textarea class="left-aligned" formcontrolname="x1" matInput placeholder="some text"/> </mat-form-field> In the co ...

Using different CSS classes interchangeably in AngularJS

Imagine you have a list with an unknown number of items, ranging from one to potentially dozens. You want to display five CSS classes in a regular alternating pattern. What would be the most effective approach to achieve this? Here is some sample HTML cod ...

Implementing event handling with .On() in Jquery following .Off()

I need assistance with my responsive navigation bar. I am having trouble with the jQuery code to disable hover events if the width is less than or equal to 768px and enable it for desktop screens. $(window).on('load resize', function (e) { v ...