Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Different rendering between inspect and view page source in browsers #818

Open
mhmdrezanaderi opened this issue Jul 8, 2022 · 3 comments

Comments

@mhmdrezanaderi
Copy link

We used twig in a project and we had html.twig file as a general layout .
We had some twig files that we used html.twig as macro in them.
now here we saw a different rendering in browsers between inspect and view page source i mean in inspect , code and location of every tag were OK but in view page source(CTRL + U), codes were in wrong form . that was funny bug i had ever seen .

After that we changed plan so we change macro to extends and used in other twig files.

U can see this bug

You can see these changes in this repository in (main,html and exercise).twig files .

https://github.com/Lo-Agency-Internship/Mhmdreza-Maryam-Mahsa-Hutan-workout-tracker-app/tree/8570dc692896a1106565ec80fdff58f29fc2353a

Now everything is OK .

@willrowe
Copy link
Collaborator

willrowe commented Jul 8, 2022

Are you able to include the Twig templates themselves and what TwigPHP rendered and then what twig.js rendered in actual text instead of screen captures?

@mhmdrezanaderi
Copy link
Author

I am a junior developer and This was our first work experience with twig. We did not use any PHP code in our project. We only use twig and js.

First of all when browser render the page everything is ok and we can't see any bug but in view page source ,we see codes in incorrect form.

We used this file as layout and created this with macro

{% macro html(addressImage) %}
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.0-beta1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-0evHe/X+R7YkIZDRvuzKMRqM+OrBnVFBL6DOitfPri4tjfHxaWutUpFmBp4vmVor" crossorigin="anonymous">
    <script  src="https://unpkg.com/alpinejs@3.10.2/dist/cdn.min.js"></script>
</head>

<body style="background-image: url('asset/image/{{addressImage}}'); height: 100vh; background-size: cover; background-position: center;background-repeat: no-repeat;">

<body>
    {% block header %}
    {% endblock %}
    {% block navbar %}
    {% endblock %}
    {% block main %}
    {% endblock %}
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.0-beta1/dist/js/bootstrap.bundle.min.js"
        integrity="sha384-pprn3073KE6tl6bjs2QrFaJGz5/SUsLqktiwsUTF55Jfv3qYSDhgCecCxMW52nD2"
        crossorigin="anonymous">
    </script>
</body>

</html>

{% endmacro %} 

And we used these files to fill the blocks

//bug was here . Instead of using macros, we should extend html.twig.
{% import "components/html.twig" as htmls %}
{{ htmls.html("bg-main.jpg")}}

{% block header %}  
{% import "components/header.twig" as headers %}
    {{headers.header()}}
{% endblock %}

{% block navbar %} 
{% import "components/navbar.twig" as navbars %} 
     {{navbars.navbar()}}
{% endblock %}

{% block main %}  
{% import "components/difCard.twig" as usersCards %}
    {{usersCards.userCard( allExercise )}}       
{% endblock %} 


// here is backend's code --> i don't remove  but U can ignore it
 <script >
  function OnLoad(){
    const checkUserId = localStorage.getItem('user-id');
    
    if(checkUserId === null)
    {
        window.location.href ='/login'
    }
    
}
window.onload= OnLoad();
    </script>

   {% set allExerciseTwig = allExercise %}
    <script>
        let  allExerciseJs = {{ allExerciseTwig|json_encode }};    
 <script>
         let  allExerciseJs = {{ allExerciseTwig|json_encode }};   
</script>

These are our codes, but if you want to see the codes in detail, ask me to send the exact repository address.

@willrowe
Copy link
Collaborator

Thank you for providing those templates. Can you please provide the raw output that twig.js is rendering these templates as and then what you expected it to be so I can see exactly what you're referring to?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants