Having trouble locating the CSS file path in my Symfony app's HTML template twig file

Embarking on a new project in symfony has been quite the learning curve for me. Despite my lack of experience, I diligently followed all the installation guidelines laid out in Symfony's documentation:

/* assets/styles/app.css */
body {
    background-color: rgb(177, 44, 44);
}
 h1{
     color: red;
 }

 h2{
     color:purple;
     border: 1px solid black;
 }
{% extends 'base.html.twig' %}

{% block body %}

    <h1> Welcome Everyone </h1>
    <h2> Welcome 2 </h2>

{% endblock %}
<!DOCTYPE html>
<html>
   <head>
       <meta charset="UTF-8">
       <title>{% block title %}Welcome!{% endblock %}</title>
        {# Run `composer require symfony/webpack-encore-bundle`
           and uncomment the following Encore helpers to start using Symfony UX #}
        <link rel="stylesheet" href="assets\styles\app.css" type="text/css">
        {% block stylesheets %}
            {#{{ encore_entry_link_tags('app') }}#}
        {% endblock %}

        {% block javascripts %}
             {#{{ encore_entry_script_tags('app') }}#}
        {% endblock %}
    </head>
    <body>
    <div class="container">
         {% block body %}{% endblock %}
    </div>
    </body>
</html>

[check out the image here][1] was successfully set up. I utilized yarn package manager to download the webpack-encore-bundle package. While I believe my () is correctly placed, my HTML file seems unable to locate the path to my CSS.

Here are the files [1]: https://i.sstatic.net/RA9FJ.png

The network browser console reports "net::ERR_ABORTED 404 (Not Found)" to me.

Answer №1

Utilizing Webpack Encore for CSS

Instead of manually adding your <link> tag, it is recommended to use the provided encore_entry_link_tags when working with Webpack Encore. This ensures that the link points to the correct file generated by Webpack Encore after running yarn encore dev.

When incorporating Webpack Encore, you can specify your CSS file in assets using addEntry('app', ...file..) or perhaps

addStyleEntry</code in the <code>webpack.config.yaml
. Webpack Encore takes care of moving the file from assets/styles/app.css to public/build (or another specified location). If any issues arise during this process, consider seeking assistance through a separate inquiry.

For additional information, refer to: https://symfony.com/doc/current/frontend/encore/simple-example.html

Alternative Method without Webpack Encore

In cases where Webpack Encore is not used, remember to utilize forward slashes in paths, such as assets/styles/app.css. To make the file accessible to the browser, ensure it resides in

public/assets/styles/app.css</code and wrap it within a helper function like <code>asset
. An example implementation could be:

<link rel="stylesheet" href="{{ path('assets/styles/app.css') }}" type="text/css">

This practice guarantees that the path remains consistent relative to the document root (public/-directory) rather than the URL. Failing to do so may result in varying paths depending on the page's location (e.g., public/assets/styles/app.css vs.

public/blog/assets/styles/app.css
).

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

Retrieve the video URL from Facebook within a WebView

Is there a way to download videos from Facebook using the video URL obtained from a Webview? I have attempted different methods to achieve this without success. 1.Link 1 2.Link 2 I tried extracting the video tag from the HTML in the Webview, however, cl ...

Tips for replacing values within an array using JQUERY

Can you please help me with replacing each value in the DOM that is currently stored in an Array? $(document).ready(function() { $(".compare-filter-item").click(function() { var column_value = $(this).attr("data-column"); var sele ...

Is AngularJS causing issues with Foundation modals? Any solutions to this problem?

Wondering how to manage Foundation4 modals with AngularJS? I've noticed that when I navigate from a modal to a new view, the old modal disappears but the page stays darkened as if it's still there in the background. I tried adding a class attribu ...

``There seems to be an issue with the AJAX form not submitting form values when it is placed within a PHP while loop

I'm encountering an issue with my code where the html form does not post values using AJAX when clicking the "submit feedback" button. The jQuery code works perfectly fine when including only a button with a value inside the form, but as soon as I try ...

Issue with input-group background display in bootstrap 4

My new computer is running on Windows 11 with Chrome version 97. There seems to be a bug in the original bootstrap code, as evidenced by the attachment. The issue can be seen on the Bootstrap website By adding "border-radius:0!important" to ".input-group ...

Developing and modifying CSS within Flex3 Air

In the process of using the Flex 3 Air application, I am in need of generating a CSS file. It is crucial that I have the ability to both create and modify the CSS file, and also be able to reach specific styles by their respective class names. If you hav ...

Node.js based simplistic static HTML web server

I'm looking to create a basic server for serving local HTML and JS files while working on development projects. I attempted to use a node app with express to respond with the page based on the URL, but unfortunately had no success. Here's my cod ...

Achieving the Perfect Alignment: Displaying Text and Progress Bar Side by Side using Bootstrap 5

How can I align the text and progress bar on the same line using Bootstrap 5? <nav class="navbar bg-light fixed-bottom"> <div class="row m-0"> <div class="col-12 countdown"> <p class=&q ...

Arranging images in a dynamic layout, either next to each other or on top of one

Currently, I am tackling a project involving two images of the human body - one for the front and one for the back. Both images are set at a height of 80vh. The challenge lies in my use of bootstrap to align these images side by side when the screen is wid ...

A guide on utilizing radio buttons to delete specific rows within a table with the help of AngularJS

My current issue involves using radio buttons to delete rows in a table. The problem I'm encountering is that multiple rows are being deleted at once instead of just one. You can view an image of my table here. As we all know, with radio buttons, onl ...

What is the name of the outlining structure in HTML5 known as?

A few days back, I came across an article discussing the usage of multiple h1 tags on the same web page. It also mentioned a specific structure that allows for multiple article, header, footer tags, and more. Unfortunately, today I'm struggling to rec ...

Invoke a JavaScript function once the div has finished loading

After clicking on a radio button, I am dynamically loading a div element. I want to hide a specific part of the div once it is loaded. $(function($) { $('.div_element').on('load', function() { $('.textbox').hide(); } ...

Unable to locate the value property of a null object

I'm currently working on creating a Shopping Cart using HTML, CSS, JavaScript, and JQuery. The idea is that when you click "Add to Cart" for the orange item, most of the HTML elements will disappear, leaving only the table displaying the Shopping Cart ...

Eliminate the space between the navigation bar and carousel when using Materialize with Vue.js and Laravel

I am facing an issue with the gap between the navbar and carousel in my materialize design. I have implemented Vue components for each div and Laravel as the backend. Using Sass for CSS preprocessing, I attempted to adjust the margins for the body, navbar, ...

Utilizing nested components with distinct styling techniques

I have a react component that accepts the size prop as either small, regular, or large. Depending on the size, a specific CSS class is assigned to style the component accordingly. Here's an example of how these classes are defined: .my-component { ...

Enhancing User Experience with AJAX-loaded Navigation Bar

I have set up the following structure: A main-page.php consisting of: 1) A header 2) A navigation bar 3) Content (loaded inside a <div id="dynamic-content"></div>) 4) Footer The navigation bar contains various options (e.g. About Us, Cont ...

Encountering a problem when trying to pass a PHP array variable to a JavaScript function

I need some help with passing an array and input value from a form to a JavaScript function. The array, $quotes, contains posts. <form method="post"> <p>Search:<input type="text" name="qSearch" id="qSea ...

Creating a drop-down menu that aligns perfectly under the bar in Material-UI: What you need to know

While working with Material-UI, I encountered a problem with my drop-down menu. Every time I click on it, it covers the bar instead of appearing below it (see image links below). https://i.stack.imgur.com/1Y8CL.jpg https://i.stack.imgur.com/emf87.jpg Is ...

Vue has limitations when it comes to applying Template Syntax to buttons

Trying to make sense of the code in my Vue Component. All elements display the template from {{ title }}, except for one lone button that stubbornly shows the template syntax as plain HTML. See Generated Page for reference Snippet of My Code: <templat ...

Ways to retrieve a particular class attribute within a less mixin

Having trouble with the .aClass? .aClass { width: 20px; height: 20px; } Looking to dynamically calculate a width value in .anotherClass based on the width of .aClass. .anotherClass { width: .aClass.width } Unfortunately, the code snippet above is no ...