|
| 1 | +--- |
| 2 | +title: Integrate GeoGebra into a Hugo website as a shortcode |
| 3 | +description: To integrate GeoGebra into a Hugo website as a shortcode, you can create a custom shortcode that embeds the GeoGebra applet using either the JavaScript method or an iframe. Here’s a step-by-step guide for both options:- |
| 4 | +date: 2025-05-17 |
| 5 | +authors: |
| 6 | + - name: Aryan |
| 7 | + link: https://github.com/simplearyan |
| 8 | + image: https://github.com/simplearyan.png |
| 9 | +tags: |
| 10 | + - Math |
| 11 | +excludeSearch: true |
| 12 | +width: nomral |
| 13 | +image: "/images/svg/github-wallpaper.svg" |
| 14 | +--- |
| 15 | + |
| 16 | +To integrate GeoGebra into a Hugo website as a shortcode, you can create a custom shortcode that embeds the GeoGebra applet using either the JavaScript method or an iframe. Here’s a step-by-step guide for both options: |
| 17 | + |
| 18 | +<!-- more --> |
| 19 | + |
| 20 | +--- |
| 21 | + |
| 22 | +## 1. Create a Custom GeoGebra Shortcode |
| 23 | + |
| 24 | +**A. Using iframe Embed (Simplest Method)** |
| 25 | + |
| 26 | +1. **Create the shortcode file:** |
| 27 | + - In your Hugo project, go to `layouts/shortcodes/geogebra.html` (or `layouts/shortcodes/geogebra-iframe.html` if you want to distinguish methods). |
| 28 | +2. **Add the following code:** |
| 29 | + |
| 30 | +```html |
| 31 | +{{ $materialID := .Get "id" | default "" }} |
| 32 | +{{ $width := .Get "width" | default "800" }} |
| 33 | +{{ $height := .Get "height" | default "600" }} |
| 34 | +<iframe |
| 35 | + src="https://www.geogebra.org/material/iframe/id/{{ $materialID }}/width/{{ $width }}/height/{{ $height }}/border/888888/sfsb/true/smb/false/stb/false/stbh/false/ai/false/sdz/false/sfbl/false" |
| 36 | + width="{{ $width }}" |
| 37 | + height="{{ $height }}" |
| 38 | + style="border:0;" |
| 39 | + allowfullscreen> |
| 40 | +</iframe> |
| 41 | +``` |
| 42 | + |
| 43 | +3. **Use the shortcode in your content:** |
| 44 | + |
| 45 | +````html |
| 46 | +{{< geogebra id="YOUR_MATERIAL_ID" width="800" height="600" >}} |
| 47 | +```` |
| 48 | + |
| 49 | + |
| 50 | +**B. Using the JavaScript Method (More Flexible, Requires Script)** |
| 51 | + |
| 52 | +1. **Create the shortcode file:** |
| 53 | + - Go to `layouts/shortcodes/geogebra-js.html`. |
| 54 | +2. **Add the following code:** |
| 55 | + |
| 56 | +```html |
| 57 | +{{ $materialID := .Get "id" | default "" }} |
| 58 | +{{ $width := .Get "width" | default "800" }} |
| 59 | +{{ $height := .Get "height" | default "600" }} |
| 60 | +<div id="ggb-element-{{ $materialID }}"></div> |
| 61 | +<script src="https://www.geogebra.org/apps/deployggb.js"></script> |
| 62 | +<script> |
| 63 | + var params = { |
| 64 | + "appName": "graphing", |
| 65 | + "width": {{ $width }}, |
| 66 | + "height": {{ $height }}, |
| 67 | + "showToolBar": true, |
| 68 | + "showAlgebraInput": true, |
| 69 | + "showMenuBar": true, |
| 70 | + "material_id": "{{ $materialID }}" |
| 71 | + }; |
| 72 | + var applet = new GGBApplet(params, true); |
| 73 | + window.addEventListener("load", function() { |
| 74 | + applet.inject('ggb-element-{{ $materialID }}'); |
| 75 | + }); |
| 76 | +</script> |
| 77 | +``` |
| 78 | + |
| 79 | +3. **Use the shortcode in your content:** |
| 80 | + |
| 81 | +````markdown |
| 82 | +<!-- {{< geogebra-js id="YOUR_MATERIAL_ID" width="800" height="600" >}} --> |
| 83 | +```` |
| 84 | + |
| 85 | + |
| 86 | +--- |
| 87 | + |
| 88 | +## Graph |
| 89 | + |
| 90 | +{{< geogebra-js id="fe9vckwu" width="800" height="600" >}} |
| 91 | + |
| 92 | + |
| 93 | +## 2. How Hugo Shortcodes Work |
| 94 | + |
| 95 | +- **Shortcodes** are templates that allow you to insert dynamic content into your Markdown files[^1][^2][^4]. |
| 96 | +- **Custom shortcodes** are placed in the `layouts/shortcodes` directory and can accept both named and positional arguments[^2][^4]. |
| 97 | +- **Usage** is straightforward: just call the shortcode name in your content, optionally passing parameters[^1][^2]. |
| 98 | + |
| 99 | +--- |
| 100 | + |
| 101 | +## 3. Additional Notes |
| 102 | + |
| 103 | +- **Security:** If you use inline shortcodes, ensure you trust your content authors and enable `enableInlineShortcodes` in your Hugo config if needed[^1]. |
| 104 | +- **Naming:** You can name your shortcode anything you like (e.g., `geogebra`, `geogebra-iframe`, `geogebra-js`)[^2][^4]. |
| 105 | +- **Parameters:** Use named parameters (like `id`, `width`, `height`) for clarity and flexibility[^2]. |
| 106 | + |
| 107 | +--- |
| 108 | + |
| 109 | +This approach allows you to easily embed GeoGebra applets in your Hugo site using shortcodes, making your content more interactive and visually engaging. |
| 110 | + |
| 111 | +<div style="text-align: center">⁂</div> |
| 112 | + |
| 113 | +[^1]: https://gohugo.io/content-management/shortcodes/ |
| 114 | + |
| 115 | +[^2]: https://gohugo.io/templates/shortcode/ |
| 116 | + |
| 117 | +[^3]: https://github.com/mfg92/hugo-shortcode-gallery/blob/master/README.md |
| 118 | + |
| 119 | +[^4]: https://www.angela1c.com/posts/2021/03/shortcodes-in-hugo/ |
| 120 | + |
| 121 | +[^5]: https://jimfrenette.com/hugo/shortcodes/ |
| 122 | + |
| 123 | +[^6]: https://roneo.org/en/hugo-install-shortcode-collection/ |
| 124 | + |
| 125 | +[^7]: https://stackoverflow.com/questions/71736142/changing-hugos-built-in-figure-shortcode-to-add-lazy-loading-to-images |
| 126 | + |
| 127 | +[^8]: https://www.siyavula.com/book-downloads/maths/Gr10_Mathematics_Learner_Eng_v11.pdf |
| 128 | + |
| 129 | +[^9]: https://dynamicland.org/archived-media/2016/02/DL2016-02-17-3eaae2.pdf |
| 130 | + |
0 commit comments