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

🤗 [Question]: #347

Closed
3 tasks done
Jhnvlglmlbrt opened this issue Feb 29, 2024 · 4 comments
Closed
3 tasks done

🤗 [Question]: #347

Jhnvlglmlbrt opened this issue Feb 29, 2024 · 4 comments
Labels
🤔 Question Further information is requested

Comments

@Jhnvlglmlbrt
Copy link

Jhnvlglmlbrt commented Feb 29, 2024

Question Description

Im having trouble embedding a function using engine.addFunc in my HTML. I have already set Auto Escape to false, but the style just doesn't seem to be applying to the HTML. Any ideas what could be going wrong?
I want to add that I use tailwindcss. Perhaps the style is simply not generated this way. But then what to do.

Code Snippet (optional)

Function - 

func CreateEngine() *django.Engine {
	engine := django.New("./views", ".html")
	engine.SetAutoEscape(false)
	engine.Reload(true)

	engine.AddFunc("badgeForStatus", func(status string) (res string) {
		switch status {
		case data.StatusOffline:
			return fmt.Sprintf(`<div class="badge badge-error">%s</div>`, status)
		case data.StatusHealthy:
			return fmt.Sprintf(`<div class="badge badge-success">%s</div>`, status)
		case data.StatusExpires:
			return fmt.Sprintf(`<div class="badge badge-warning">%s</div>`, status)
		case data.StatusExpired:
			return fmt.Sprintf(`<div class="badge badge-error">%s</div>`, status)
		case data.StatusInvalid:
			return fmt.Sprintf(`<div class="badge badge-error">%s</div>`, status)
		}
		return ""
	})
}

Html file - 

                    <tr>
                        <th>Status</th>
                    </tr>
                </thead>
                <tbody>
                    {% for tracking in trackings %}
                    <tr>
                        <td>{{(badgeForStatus(tracking.Status))}}</td>
                    </tr>
                    {% endfor %}
                </tbody>

Checklist:

  • I agree to follow Fiber's Code of Conduct.
  • I have checked for existing issues that describe my questions prior to opening this one.
  • I understand that improperly formatted questions may be closed without explanation.
@Jhnvlglmlbrt Jhnvlglmlbrt added the 🤔 Question Further information is requested label Feb 29, 2024
@ReneWerner87
Copy link
Member

@Jhnvlglmlbrt
what is the HTML output after it is rendered ?

@Jhnvlglmlbrt
Copy link
Author

Jhnvlglmlbrt commented Feb 29, 2024

have you tried https://docs.djangoproject.com/en/dev/ref/templates/builtins/#autoescape

or the safe pipeline see #326 (comment) -> https://github.com/gofiber/template/tree/master/django#setting-autoescape-using-django-built-in-template-tags

I see that -

<td><div class="badge badge-success">healthy</div></td>

I used engine.SetAutoEscape(false). There is no need for autoescape. I guess the problem in tailwindcss. Its just cant compile that html into css.

@ReneWerner87
Copy link
Member

okay, but then it has nothing to do with our template engine and everything works as expected

please contact the software experts of the other systems

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🤔 Question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants