Comments (11)
Here's some more discussion on a similar issue: https://stackoverflow.com/questions/64113404/bootstrap-5-referenceerror-bootstrap-is-not-defined
The parent Understrap theme calls the module like export { default as Carousel } from 'bootstrap/js/src/carousel';
and the child Understrap-Child theme does it like import Carousel from 'bootstrap/js/dist/carousel
then export {Carousel}
Given that, I tried:
let testimonialCarousel = new bootstrap.Carousel(document.getElementById('#testimonial-carousel'));
testimonialCarousel.show();
But then get "Uncaught ReferenceError: Carousel is not defined"
So how do we call Bootstrap modules?
from understrap.
Is
let testimonialCarousel = new bootstrap.Carousel(document.getElementById('#testimonial-carousel'));
testimonialCarousel.show();
a separate script or is it bundled in theme.js?
from understrap.
from understrap.
Then using let testimonialCarousel = new understrap.Carousel(document.getElementById('#testimonial-carousel'));
instead will most likely solve the problem.
The name of the bundle is set in rollup.config.js
understrap/src/build/rollup.config.js
Line 76 in 1a9b9af
So it might be different from "understrap" in a child theme.
from understrap.
Thanks @IanDelMar and great to see your name here. That did the trick. Is this a normal / expected way to call a module wrapped up in an application like this? I ask because this flummoxed two developers for a week. Maybe we're just not that experienced, but this seems like an unexpected way of calling a packaged module.
-Alex
from understrap.
Great it works!
great to see your name here
It took me a while to figure out what this was about 😄 I didn't recognise you at first.
Is this a normal / expected way to call a module wrapped up in an application like this?
I guess it depends on your typical use cases. This might make sense if you think of Understrap as a starter theme. Then, often, the bundle's name is irrelevant. You import the Carousel component into your js-file and use new Carousel()
instead of new bundleName.Carousel()
. And if you split the script into different files, you usually know the bundle's name.
If you think of Understrap as a parent theme that has to provide all of Bootstrap's JS, it would probably be best to ship the pre-built Bootstrap dist files. I have never used it as a parent theme.
from understrap.
Related: #1583
from understrap.
Closing this now that we've added a note to the docs about this. Feel free to reopen if there's anything I missed
from understrap.
Thanks @bacoords
We're still struggling with this. It seems so unnecessarily complicated!
We're now trying to initialize and show toasts.
If we add this to the footer, it works fine:
<script>
const sessionToastEl = document.getElementById('session-toast');
if (sessionToastEl) {
const sessionToast = new understrap.Toast(sessionToastEl);
sessionToast.show()
}
</script>
But if we add the same thing to custom-javascript.js and compile (which is what I thought was the intended workflow), it says "understrap is not defined".
Am I missing something? Why is this so complicated? Can we just call bootstrap constructors the regular way?
Thanks!
from understrap.
Okay after looking more closely at 1583 I have made this work in custom-javascript.js
import Toast from 'bootstrap/js/dist/toast'
const sessionToastEl = document.getElementById('session-toast');
if (sessionToastEl) {
const sessionToast = new Toast(sessionToastEl);
sessionToast.show()
}
Thanks for more carefully noting this. It all does seem quite confusing. I wish the process were more clear. Anywhoo, I'm not one to do the work of making it more clear, so I shouldn't complain!
-Alex
from understrap.
We're still struggling with this. It seems so unnecessarily complicated!
Sorry to hear that. Are you using a custom set of Bootstrap JS components? If not, perhaps using Bootstrap as is is an option? If so, one option would be to compile the Bootstrap source files separately and name the bundle "bootstrap". Either way would ensure that you can use Bootstrap as described in the Bootstrap documentation. Let me know if you need help setting up the build process for any of these options.
from understrap.
Related Issues (20)
- Woocommerce Mini Cart Widget Stopped working with Understrap theme HOT 2
- Please provide a short summary of the problem (approx. 50 characters) HOT 6
- Theme contains outdated copies of Woocommerce template files HOT 5
- I can't figure out a way to make tagline appear in the header area. HOT 2
- RollupError: Unexpected character '@' HOT 4
- Potential typo in phpstan.neon.dist HOT 1
- Add IE Support for using bootstrap container classes in the block editor
- outdated woocommerce template files HOT 6
- The style.min.css file is not being linked to the page HOT 4
- npm run watch is not working HOT 13
- Feature Request: Add `.nvmrc` file with the needed version of node/npm HOT 3
- wordpress navbar toggle not working after log out HOT 4
- Can we customize understrap_post_nav(); so it only gets prev/next from a specific category? HOT 18
- How to properly add additional js files HOT 1
- Release 1.2.4 Tracking Issue HOT 4
- Update to WPCS 3.0 (w/ PHP 8.2 support)
- Unable to build or run understrap projects - SyntaxError: Unexpected token '?' in file node_modules/lilconfig/src/index.js:161 HOT 1
- Optimize color palette generation for improved performance
- 5.3 Support HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from understrap.