gofiber / template

🧬 Template engine middleware for Fiber
https://docs.gofiber.io/guide/templates
MIT License
260 stars 52 forks source link

django template cannot find included template? #79

Closed mikeychowy closed 3 years ago

mikeychowy commented 3 years ago

The error: views: [Error (where: fromfile) in ./partials/desktop_sidebar.html | Line 21 Col 18 near './partials/desktop_sidebar.html'] unable to resolve template

main.html in ./public/layouts folder, the partial is inside another folder called partials in this folder(./partials/):

<html :class="{ 'theme-dark': dark }" x-data="data()" lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>{{pageTitle}}Louve Admin Area</title>
    <link
      href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap"
      rel="stylesheet"
    />
    <link rel="stylesheet" href="/assets/admin/css/tailwind.output.css" />
    <script src="/assets/admin/js/alpine.min.js" defer></script>
    <script src="/assets/admin/js/init-alpine.js"></script>
    <link rel="stylesheet" href="/assets/admin/css/Chart.min.css" />
    <script src="/assets/admin/js/Chart.min.js" defer></script>
    <script src="/assets/admin/js/charts-lines.js" defer></script>
    <script src="/assets/admin/js/charts-pie.js" defer></script>
  </head>
  <body>
    <div class="flex h-screen bg-gray-50 dark:bg-gray-900" :class="{ 'overflow-hidden': isSideMenuOpen }">
      {% include "partials/desktop_sidebar.html" %} {% include "partials/mobile_sidebar.html" %}
      <div class="flex flex-col flex-1 w-full">
        {% include "partials/header.html" %} {% block content %}{% endblock %}
      </div>
    </div>
    {% if withModal %} {% include "partials/modal.html" %} {% endif %}
  </body>
</html>

It seems that the include syntax is unsupported by pongo2 or there's something wrong with my initialization of the engine? I did it like this:

engine := django.New("public", ".html"))

I have a public folder like this:

public 
    -- admin
          -- assets
          -- layouts
                -- partials
    -- pub
    - admin-index.html

My intention is to separate the admin area templates with actual public templates, does this setup need an embedded filesystem instead of just plain location string?

mikeychowy commented 3 years ago

Nevermind this question, dumb dumb on my part. Turns out since public is used as the root i needed to access the partial as "admin/layouts/partial/partial_name".