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

Can you provide example of RawTag? #2

Open
aok1425 opened this issue Sep 27, 2015 · 2 comments
Open

Can you provide example of RawTag? #2

aok1425 opened this issue Sep 27, 2015 · 2 comments

Comments

@aok1425
Copy link

aok1425 commented Sep 27, 2015

I've tried implementing a RawTag object, but can't figure it out by looking through the source code.

I've tried

  • RawTag("<img src='http://www.w3schools.com/images/colorpicker.gif'>")
  • RawTag('http://www.w3schools.com/images/colorpicker.gif', type='img')

but they don't work.

Can you provide an example in the README/demo?

thanks!

@mbr
Copy link
Owner

mbr commented Sep 27, 2015

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?

@albfan
Copy link

albfan commented Feb 12, 2020

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

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

No branches or pull requests

3 participants