Giter Site home page Giter Site logo

Can you provide example of RawTag? about flask-nav HOT 2 OPEN

mbr avatar mbr commented on September 2, 2024
Can you provide example of RawTag?

from flask-nav.

Comments (2)

mbr avatar mbr commented on September 2, 2024

That seems to be bug at the moment, it's missing an implementation in the Renderer.

For now, you'll have to subclass the Renderer and add a visit_RawTag method. However, RawTag is, if I remember correctly, not used and just a leftover from when other classes inherited from it. This is not a good state of affairs, I'll have to change the API somewhat, removing raw tag and adding another method to add raw stuff.

In the meantime, maybe sublcassing a Renderer and a NavigationItem (see http://pythonhosted.org/flask-nav/advanced-topics.html#implementing-custom-renderers) is what you need?

from flask-nav.

albfan avatar albfan commented on September 2, 2024

FTR:

Trying to add a button on navbar (login from popup, taken from bootstrap examples):

from flask_bootstrap.nav import BootstrapRenderer
from dominate import tags
from dominate.util import raw

class BootstrapRawTagRenderer(BootstrapRenderer):
    def visit_RawTag(self, node):
        return tags.li(raw(node.content))

app = Flask(__name__)
register_renderer(app,'bootstrap_rawtag', BootstrapRawTagRenderer)
...

@nav.navigation() 
def navbar(): 
    return Navbar('My Project', View('About', 'about'), RawTag('<button type="button" id="loginButton" class="btn btn-primary" data-toggle="modal" data-target="#loginModal">Login</button>'))

In your templates:

{% block navbar %}
{{ nav.navbar.render(renderer='bootstrap_rawtag') }}
{% endblock %}

{% block content %}
...
<div class="modal fade" id="loginModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
        <h5 class="modal-title" id="exampleModalLabel">Login</h5>
      </div>
      <div class="modal-body">
        <form method="post" action='/login/' name="login_form">
          <p><input type="text" class="span3" name="eid" id="email" placeholder="Email"></p>
          <p><input type="password" class="span3" name="passwd" placeholder="Password"></p>
          <p><button type="submit" class="btn btn-primary">Sign in</button>
            <a href="#">Forget the password?</a>
          </p>
        </form>
      </div>
      <div class="modal-footer">
        Do you want to register?
        <a href="#" class="btn btn-primary">Register</a>
      </div>
    </div>
  </div>
</div>

{% endblock %}

@mbr I understand that allow this dominate.util.raw() is scary, but wrap everything from flask_nav seems to big to not consider this RawTag.

Let me know if you consider to accept a PR related to that

from flask-nav.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.